Search code examples
buttonunity-game-engineunityscripthittest

Why does not enter if loops?


I just want to make restart button with touch button via below code, but if statment does not work. Could you find reason?

function OnGUI() {
    if(Input.touchCount>0) {

        if (GUI.Button(Rect(Screen.width/1.12, 0, Screen.width/8, Screen.height/8),"restart")) {

            Application.LoadLevel(1);
        }
    }
}

Solution

  • From what i see. The button wont even show up unless they already have at least a finger down. It isnt working doesnt tell me anything. Is the button showing up at all or does nothing happen when you attempt to hit it?

    Im not sure if UGUI ifs work different on mobile devices but NGUI is worth a look at. Not sure if its still free but it makes setting up UIs easier imo.

    Hope this helps.