Application

Please help me! Can not understant what is not right!

using UnityEngine;
using System.Collections;

public class STARTLEVEL : MonoBehaviour {
	public bool LoadLevel = false;
	
	void OnClick()  {

		if( LoadLevel = true){
		Application.LoadLevel(1);
	}
	    else if ( LoadLevel = false){
	    Application.Quit();
    }
  }
}

It helps if you tell the error you’re getting. By looking at this I would say you made a bool called LoadLevel, and trying to use a function that already has the name LoadLevel. Try to make the bool LoadLevel to lowercase, like loadLevel.

You are using the assignment operator ‘=’ instead of the comparison operator ‘==’ in your conditional checks. They will always return true if you don’t change them to comparison operators.

Unity has no OnClick function, so that code will never run.

–Eric

I am using NGUI There is no erro. But it simply does not work. I want if i have boole = true ( Application.LoadLevel) if not ( Application.Quit)

As DanielQuick pointed it out, change your if conditions and use == instead of = because like this you’re changing the value of LoadLevel to true instead of comparing the value, so it always does Application.LoadLevel regardless of what’s the value set in the inspector…

Hint: always use the constant first in the comparison.

if (true == LoadLevel)
    ...

this way you get an error from the compiler if you accidentially use the assignment operator. it takes a bit to turn this into an habit but its worth it.

also you don’t need an else if as there is only one other possibility. so an else does the same.

that is a really nice trick but I can’t imagine writing code like that!

Thanks a lot to everyone!

with bools, you can just say
if(someBool) { …

its the same as
if(someBool == true) { …