x


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();
       }
    }
}
more ▼

asked Jul 01 '12 at 12:25 AM

kmccmk9 gravatar image

kmccmk9
31 17 29 31

@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.

Jul 01 '12 at 07:18 AM hijinxbassist

That makes sense. Thank you

Jul 01 '12 at 07:23 AM kmccmk9
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Try : if (GUI.Button(new Rect(10, 500, 500, 300), PlayButton)) {

more ▼

answered Jul 01 '12 at 02:17 AM

Chimera3D gravatar image

Chimera3D
479 16 34 48

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3676
x1944
x819
x786
x385

asked: Jul 01 '12 at 12:25 AM

Seen: 309 times

Last Updated: Jul 01 '12 at 09:58 AM