I need help trying to input number's into the coding here is what I'm trying to do:
If you press the number one it will choose a weapon. If you press the number one again it will choose another weapon. The cycle continues as you keep pressing the number one. If you guys could show me what code could make this happen that would be awesome.
Here is what I got I am so lost
var projectile : GameObject;
function Start ()
{
}
function Update ()
{
if(Input.GetButtonUp("1"))
{
print("axe");
}
}
Replies
var counter:int = 0; var weaponArr:string[] = ["axe", "knife", "someOtherThing"]; var weaponCount:int; function Start() { weaponCount = weaponArr.length; } function Update() { if(Input.GetButtonDown("1")) //Down is likely preferable to Up in this case { counter++; //increment the global counter print(weaponArr[counter % weaponCount]); // % is modulo, which is handy to "loop" a counter } }Switch(counter % weaponCount) { case 0: //stuff break; case 1: //stuff break; case 2: //stuff break; etc }