Simple if condition in function not turning off

Hi everyone,

I’m sitting with what must be a pretty simple problem that I just cant seem to figure out.

My code:

function OnGUI () {



function SwitchOnObject ( object : GameObject) {

	var objectSwitchedOn : boolean = false;

	if (!objectSwitchedOn) { 
		objectSwitchedOn = true;

The if condition wont turn off even though I set the boolean to true, any ideas?

Your variable is declared inside the function. So its value is reseted each time the function is called.

You have to declare it outside the function as a private member of your class.

You should learn the base of programming

Good luck :wink: