/// <summary> /// Equip a new gun /// </summary> /// <param name="gunToEquip">Gun to equip</param> /// <param name="skipEquipTime">Whether equip time is skipped</param> public void EquipGun(Gun gunToEquip, bool skipEquipTime = false) { // Can only equip gun when previous gun is ready if (state == GunControllerState.EQUIPPING) { return; } if (equippedGun != null) { Destroy(equippedGun.gameObject); } // Prevent switching to gun player does not have equippedGunIndex = guns.FindIndex(x => x == gunToEquip); if (equippedGunIndex < 0) { return; } // Equip weapon into player hand state = GunControllerState.EQUIPPING; float equipDelay = skipEquipTime ? 0 : GunEquipTime; Wait(equipDelay, () => { equippedGun = Instantiate(gunToEquip, weaponTransform.position, weaponTransform.rotation, weaponTransform); state = GunControllerState.READY; }); }
private void Start() { // Equip first gun if none is equipped if (!hasGunEquipped && guns.Count > 0) { EquipGun(guns[0], true); } else { state = GunControllerState.READY; } }