- Home /
weapon switching
so basicaly im making a simple game to test some stuff ive made and get more experience and then just continue building on it, I have five different weapons total for the player to use (a sword, a dagger, an axe, a spear, and a bow). I have them all attached to the players camera (using the first persom controller prefab) how do I make it so only one appears at a time and only that weapon can be used but the player can switch to a different weapon at any time? any help with this will be greatly appreciated.
Answer by Berenger · Jun 11, 2012 at 03:33 PM
Probably as many ways as your imagination can come up with. Here is one
// Create a var of that type on your weapons and assign them correctly
public enum WeaponType{ Sword, Dagger, Axe, Spear, Bow }
// inside the class that does the switch
public void SwitchTo( WeaponType wt )
{
// I suppose they are stored in an array in WeaponType's order
for(int i = 0; i < weapons.Length; i++) weapons[i].gameObject.active = false;
weapons[ (int)wt ].gameObject.active = true;
}
Your answer
Follow this Question
Related Questions
Weapon Switch 1 Answer
gun switch script 26-feb-2010 1 Answer
Switch Case for Basic AI.... 1 Answer
Making A Script for my Switch 1 Answer