Hey guys, I’m a little baffled at why the following code does no compile:
using UnityEngine;
using System.Collections;
public class MainTitle : MonoBehaviour
{
// Use this for initialization
void Start()
{
}
// Update is called once per frame
void Update()
{
}
void OnGUI()
{
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), “This is a title”);
}
}
Am I missing something? As far as I’m aware, the GUI class most certainly contains a definition for Box. It’s in every tutorial and every example I can find online!
I’m just trying to make a simple GUI for a class assignment. Anyone have any thoughts on why this isn’t working? Maybe I need to import something?
Thanks for your help,
Fred
What is the error?
As far as I can tell the script is ok, and attached to any object it should work.
Ah, the error would probably be helpful.
There must be something wrong with my environment(I’m guessing?), or something, because the error I get is:
‘GUI’ does not contain a definition for ‘Box’.
I’m using C#. Do I maybe need to declare it in some special way? Do I need to import anything?
I hear “It should work” all around, but Unity remains displeased!
-Fred
It seems like GUILayout is working correctly, but not GUI.
This code compiles and works:
GUILayout.BeginArea(new Rect(10, 10, 100, 100));
GUILayout.Button(“Click me”);
GUILayout.Button(“Or me”);
GUILayout.EndArea();
But this code does not:
GUI.Box(new Rect(0, 0, Screen.width, Screen.height), “This is a title”); //Error: GUI' does not contain a definition for Box’
GUILayout.Box(new Rect(0, 0, Screen.width, Screen.height)); //Error: The best overloaded method match for `UnityEngine.GUILayout.Box(UnityEngine.Texture, params UnityEngine.GUILayoutOption[ ])’ has some invalid arguments
Thanks again!
-Fred
Do you have a script in your project called GUI? If not, does anything else from GUI work?