- Home /
Question by
22andrew22 · Apr 11, 2012 at 10:26 AM ·
javascriptfpsswitchbooleans
FPS main and side weapon question
I have an equip script, that equips weapons based on what game object you click on. Weapons have a "class" with different parameters such as damage, max ammo... etc. I'm using an boolean to see if its active and I need to know how to "switch from main gun to a sidearm." IE, user presses 1, and the main gun that is equipped becomes active, and when the user presses 2, the sidearm becomes active and the main gun becomes inactive. Any ideas?
Comment
Wiki
Answer by NickWalker12 · Apr 11, 2012 at 12:07 PM
if(Input.GetButtonDown("1") //"1" is the name you put in Edit->Project Settings->Input
{
if(!Primary.IsActive)
{
Primary.IsActive = true;
Current.IsActive = false;
}
}
else if(Input.GetButtonDown("2")
{
if(!Secondary.IsActive)
{
Secondary.IsActive = true;
Current.IsActive = false;
}
}
Your answer