where do the brackets go?

this probably seems like a noob question, but i forgot where the brackets go lol and now i have errors and i cant remember, heres my script

var weapon = 0;

function Update () {
}

function OnGUI () {
	if (GUI.Button (Rect (10,10,160,100), "Machineguns")) {
		(var weapon == 1);
	}
	if (GUI.Button (Rect (10,170,330,100), "Flamethrower")) {
		(var weapon == 2);
	}
	if (GUI.Button (Rect (10,330,490,100), "Cannon")) {
		(var weapon == 3);
	}
}

the brackets on the var weapon == 1;

1 Answer

1

remove "==" and write "=", you are not in an if condition. Brackets are correct.

You also have to remove var, or you'll instantiate a new variable. For short, do "if (...) { weapon=x; }", for all the 3 tests, with x=1, 2 or 3.

okey i have this now var weapon = 0; function Update () { } function OnGUI () { if (GUI.Button (Rect (10,10,160,100), "Machineguns")) { (weapon = 1); } if (GUI.Button (Rect (10,170,330,100), "Flamethrower")) { (weapon = 2); } if (GUI.Button (Rect (10,330,490,100), "Cannon")) { (weapon = 3); } } all the errors are still there though

Brackets around "weapon=x" are unuseful...I don't think that's the problem, but try to remove them. However, if that's not the case, I can't figure the error out. Can you post the compiler's output, so we can view the specific error that you receive?

remove the brackets on your variable setting. so instead of: (weapon = 1); just put weapon = 1;

thankyou, fixed now