Exemplo n.º 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);
    }
Exemplo n.º 2
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);
    }