mirror of
				https://github.com/DerTyp7/defrain-shooter-unity.git
				synced 2025-11-04 15:18:59 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.1 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
using System.Collections;
 | 
						|
using System.Collections.Generic;
 | 
						|
using UnityEngine;
 | 
						|
 | 
						|
public class Ammunition : MonoBehaviour
 | 
						|
{
 | 
						|
 | 
						|
    // Start is called before the first frame update
 | 
						|
    void Start()
 | 
						|
    {
 | 
						|
        
 | 
						|
    }
 | 
						|
 | 
						|
    // Update is called once per frame
 | 
						|
    void Update()
 | 
						|
    {
 | 
						|
        
 | 
						|
    }
 | 
						|
 | 
						|
    public bool subtractAmmunition(Weapon weapon)
 | 
						|
    {
 | 
						|
        if (weapon.CurrentAmmunition > 0) {
 | 
						|
            weapon.CurrentAmmunition -= 1;
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
 | 
						|
    public bool reloadWeapon(Weapon weapon)
 | 
						|
    {
 | 
						|
        if (weapon.AllowAction && weapon.TotalAmmunition > 0) {
 | 
						|
            weapon.AllowAction = false;
 | 
						|
            int dif = weapon.MagazinSize - weapon.CurrentAmmunition;
 | 
						|
 | 
						|
            if (weapon.TotalAmmunition >= dif) {
 | 
						|
                weapon.CurrentAmmunition += dif;
 | 
						|
                weapon.TotalAmmunition -= dif;
 | 
						|
            }
 | 
						|
            else {
 | 
						|
                weapon.CurrentAmmunition += weapon.TotalAmmunition;
 | 
						|
                weapon.TotalAmmunition = 0;
 | 
						|
            }
 | 
						|
            weapon.AllowAction = true;
 | 
						|
            Debug.Log("Reloaded");
 | 
						|
            return true;
 | 
						|
        }
 | 
						|
        return false;
 | 
						|
    }
 | 
						|
}
 |