public void Switch(int direction) { if (direction == 0) { return; } if (Guns.Count <= 1) { return; } if (EquippedGun == null) { EquippedGun = Guns [0]; EquippedGun.OnEquip(gameObject); EquippedGun.equipped = true; return; } EquippedGun.equipped = false; EquippedGun.OnUnequip(gameObject); // Oh my god % is not actually modulo. Why would you do this C#??? //EquippedGun = Guns [(Guns.IndexOf(EquippedGun)+direction)%Guns.Count]; EquippedGun = Guns [(int)Helper.fmod(Guns.IndexOf(EquippedGun) + direction, Guns.Count)]; EquippedGun.OnEquip(gameObject); EquippedGun.equipped = true; }
void Awake() { foreach (GunBase gun in Guns) { gun.OnUnequip(gameObject); gun.equipped = false; } if (EquippedGun != null) { if (!Guns.Contains(EquippedGun)) { Guns.Add(EquippedGun); } EquippedGun.OnEquip(gameObject); EquippedGun.equipped = true; } }
void OnTriggerEnter(Collider other) { GunBase gun = other.gameObject.GetComponent <GunBase> (); if (gun != null && !Guns.Contains(gun)) { Guns.Add(gun); if (EquippedGun == null) { EquippedGun = gun; EquippedGun.OnEquip(gameObject); EquippedGun.equipped = true; } else { other.gameObject.SetActive(false); } } }