- Home /
How can i have 3 weapon to switch between??
hi i have an axe, sword and a crossbow in my RPG game, but can't switch between more than two weapons?? here my script.
#pragma strict
var Weapon01 : GameObject;
var Weapon02 : GameObject;
var Weapon03 : GameObject;
var TheAxe : Transform;
var TheSting : Transform;
function Update () {
if (Input.GetKeyDown(KeyCode.Q))
{
SwapWeapons();
}
}
function SwapWeapons()
{
if (Weapon01.active == true)
{
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(true);
Weapon03.SetActiveRecursively(false);
TheSting.animation.Play("Switch");
}
else
{
Weapon01.SetActiveRecursively(true);
Weapon02.SetActiveRecursively(false);
Weapon03.SetActiveRecursively(false);
TheAxe.animation.Play("Switch");
}
else
{
Weapon01.SetActiveRecursively(false);
Weapon02.SetActiveRecursively(false);
Weapon03.SetActiveRecursively(true);
TheCrossbow.animation.Play("Switch");
}
}
and i got this error:
Assets/Standard Assets/weaponSwitching.js(32,9): BCE0044: expecting }, found 'else'. and Assets/Standard Assets/weaponSwitching.js(34,53): BCE0044: expecting :, found ';'.
Answer by roojerry · May 06, 2013 at 05:43 PM
if statements can only have one "else" case, but can have multiple "else if" cases.
so your second else should be:
else if (Weapon02.active == true)
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Weapon customize system 1 Answer
Plugin Container for Firefox/Unity Web Player crash whenever I try to load Dead Trigger 2 0 Answers
Game object position. 1 Answer
I made a better shader how do i fix[add _Shadow Strength]help???>Sorry that im asking for to much 1 Answer