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); } }
//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); }