I’m creating a 2D game for iOS using Sprites, and have a ‘Play’ button on the main menu scene. I want to load the next screen when the play button is tapped, and have used the following script:
function Update(){
if ((Input.touchCount == 1) &&
(Input.GetTouch(0).phase == TouchPhase.Began) )
{
Application.LoadLevel("level1");
}
}
The code works fine, but when the screen is tapped anywhere, ‘level1’ is loaded. I just the button to register the input. I attached the code to the sprite which I am using for my button, and also tried attaching it to a gameobject infront of the sprite, but with no mesh renderer. I can still tap anywhere on the screen to load the next level, but only want to load level if the button is pressed.
Any ideas how to prevent this?
Thanks.