- Home /
'Button' is not a member of 'GUI'
I have developed some "so called" games from Unity3d using GUI system.However, today when I wrote some code that deals with GUI I got errors saying 'Button' is not a member of 'GUI'. So, as a normal user I went on to scripting docs and copied their script, pasted on to my script and still the same error.. What's wrong with it? I've used Unity to make GUIs several times but this is the first time I'm facing this problem...
Here's the script
#pragma strict
var cam1:boolean;
var cam2:boolean;
var cam3:boolean;
function Start () {
}
function Update () {
}
function OnGUI(){
if(GUI.Button(Rect(10,10,50,50),"Camera 1"))
{
cam1=true;
cam2=false;
cam3=false;
}
if(GUI.Button(Rect(10,30,50,50),"Camera 2"))
{
cam2=true;
cam1=false;
cam3=false;
}
if(GUI.Button(Rect(10,60,50,50),"Camera 3"))
{
cam3=true;
cam1=false;
cam2=false;
}
//Part copied from unity docs-->
if (GUI.Button(Rect(10,10,50,50),"asd"))
Debug.Log("Clicked the button with an image");
}
Answer by Eric5h5 · Aug 22, 2012 at 04:21 PM
Don't call your script GUI, otherwise Unity can't tell the difference between your GUI class and the built-in GUI class. (Technically you can distinguish by referring to UnityEngine.GUI, but that's kind of clunky and it's better just to avoid this in the first place.)