- Home /
 
Expecting variable error with a button
Hello,
I have a code for a menu system. I can't see what's wrong but it keeps telling me my first if statement is wrong it is expecting a variable not a type. Can anyone help me?
 using UnityEngine;
 using System.Collections;
 
 public class Menu : MonoBehaviour {
     public Texture MainMenuBackground;
     public Texture PlayButton;
     public Texture QuitButton;
     // Use this for initialization
     void Start () {
         
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     
     void OnGUI() {
         GUI.DrawTexture(new Rect(0,0,Screen.width,Screen.height),MainMenuBackground,ScaleMode.StretchToFill, false, 0.0f);
         
         if (GUI.Button(Rect(10,500,500,300),PlayButton)) {
             Application.LoadLevel("FirstRoom");
         }
         if (GUI.Button(Rect(50,700,500,300),QuitButton)) {
             Application.Quit();
         }
     }
 }
 
              
               Comment
              
 
               
              @Noob-e is correct, C# needs initializers for any new object value. This includes a rect or vector3 or what have you. Always make sure to add the 'new' keyword for new values.
 
               Best Answer 
              
 
              Answer by Chimera3D · Jul 01, 2012 at 02:17 AM
Try : if (GUI.Button(new Rect(10, 500, 500, 300), PlayButton)) {
Your answer
 
             Follow this Question
Related Questions
Bool script error 1 Answer
How do I use my .png file as a button? 1 Answer
My GUI buttons are triggering without user input. 1 Answer
Annoying warning with GUI, quick fix? 2 Answers