- Home /
Button activating before clicking
Hi. I am following a 2d space shooter tutorial in c#. does anyone know how to fix it so i have to click the button for it to activate? thxxx.
i use notepad++ and have unity 4.2. when i was making the main menu to link to level one, as soon as i click play the button activates.
using UnityEngine; using System.Collections; //go to folders, copy, paste, and change name in notepad and at folder. public class MainMenu : MonoBehaviour {
#region Feilds
private string instructionText = "Intsructions:\nPress Left and Right Arrows to move.\nPress Spacebar to fire.";
private int buttonWidth = 200;
private int buttonHeight = 50;
#endregion
#region Properties
#endregion
#region Functions
void OnGUI ()
{
GUI.Label(new Rect(10, 10, 250, 200), instructionText);
if (GUI.Button(new Rect((Screen.width / 2) - (buttonWidth / 2),
Screen.height / 2 - buttonHeight / 2, buttonWidth, buttonHeight), "Start Game"));
{
Application.LoadLevel(1);
}
}
#endregion
}
Answer by robertbu · Oct 12, 2013 at 12:57 AM
At the end of line 19, you have a ';' that should not be there. Remove the ';' and you code should work fine.
Your answer
Follow this Question
Related Questions
Button then instanitates gameobject 1 Answer
Creating GUI 1 Answer
How do Text Fields work? (Backend) 1 Answer
Limiting object rotation using GUI.Buttons? 1 Answer
Can I use the new GUI system with instantiated prefabs? 1 Answer