예제 #1
0
    void ChangeWeapon()
    {
        RangedWeapon otherWeapon;

        if (currentWeapon == primaryWeapon && baseWeapon != null)
        {
            otherWeapon = baseWeapon;
            anim.SetBool("Primary", false);
        }
        else if (currentWeapon == baseWeapon && primaryWeapon != null)
        {
            otherWeapon = primaryWeapon;
            anim.SetBool("Primary", true);
        }
        else
        {
            return;
        }

        //Deactivate current weapon
        currentWeapon.OnAmmoChanaged -= CurrentWeapon_AmmoChanged;
        currentWeapon.IsBeingUsed(false);

        currentWeapon = otherWeapon;

        //Activate new weapon
        currentWeapon.Reset();
        currentWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged;
        currentWeapon.IsBeingUsed(true);
        OnAmmoChanged?.Invoke(CurrentWeapon.Magazine);
    }
예제 #2
0
    void Awake()
    {
        anim = GetComponent <Animator>();
        col  = GetComponent <Collider>();
        rb   = GetComponent <Rigidbody>();

        //To drag in character and test easier
        if (Player == null)
        {
            Player = new Player();
            SetupPlayer(Player);
        }

        //Subscribe to stat events
        stats.OnDeath       += Stats_OnDeath;
        stats.OnStatChanged += Stats_OnStatChanged;

        //Equip base weapon if any
        if (baseWeapon != null)
        {
            baseWeapon.Equip(weaponParent);
            currentWeapon              = baseWeapon;
            baseWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged;
            OnAmmoChanged?.Invoke(baseWeapon.Magazine);
        }
    }
예제 #3
0
    //TODO: Make one Equip method for each type of equippable
    /// <summary>
    /// Returns false if Weapon is null
    /// </summary>
    public bool EquipWeapon(Weapon weap)
    {
        if (weap == null)
        {
            return(false);
        }

        if (weap is RangedWeapon)
        {
            //Equip new weapon
            RangedWeapon rangedWeap = weap as RangedWeapon;
            anim.SetBool("Primary", true);
            currentWeapon?.IsBeingUsed(false);
            rangedWeap.Equip(weaponParent);

            if (PrimaryWeapon != null)
            {
                Destroy(PrimaryWeapon.gameObject);
            }

            currentWeapon = primaryWeapon = rangedWeap;
            primaryWeapon.OnAmmoChanaged += CurrentWeapon_AmmoChanged;
            OnAmmoChanged?.Invoke(primaryWeapon.Magazine);
            return(true);
        }
        return(false);
    }
예제 #4
0
 private void Update()
 {
     if (Input.GetButton("Fire1") && Time.time > canFire)
     {
         ammoCount--;
         OnAmmoChanged?.Invoke(ammoCount);
         canFire = Time.time + fireRate;
     }
     else if (Input.GetButtonUp("Fire1"))
     {
         canFire = Time.time;
     }
 }
예제 #5
0
 public bool TrySpendAmmo()
 {
     if (ammo > 0)
     {
         ammo--;
         OnAmmoChanged?.Invoke(this, EventArgs.Empty);
         return(true);
     }
     else
     {
         return(false);
     }
 }
예제 #6
0
 private void Start()
 {
     ammoCount = maxAmmoCount;
     OnAmmoChanged?.Invoke(ammoCount);
 }
 public void HandleOnAmmoChanged()
 {
     OnAmmoChanged?.Invoke();
 }
예제 #8
0
 /// <summary>
 /// Calls the OnAmmoChanged event when the current weapons OnAmmoChanged event is called
 /// </summary>
 /// <param name="mag">The current magazine</param>
 void CurrentWeapon_AmmoChanged(Magazine mag)
 {
     OnAmmoChanged?.Invoke(mag);
 }
예제 #9
0
파일: GameEvents.cs 프로젝트: zimpzon/GFun
 public static void RaiseAmmoChanged(AmmoType ammoType, int change) => OnAmmoChanged?.Invoke(ammoType, change);
예제 #10
0
 public void Reload()
 {
     ammo = GetAmmoMax();
     OnAmmoChanged?.Invoke(this, EventArgs.Empty);
 }