I have a simple cube, flattened out, with a material that is the background image.
Now, I place 2 GUI Textures in the scene, and I want to click them to do something (Load the first level scene, load a help scene, etc.)
I have tried several “tutorials” on the subject, but I am falling way short. Any help is appreciated.
Here’s what I have this far (nearly nothing other than the public bits):
public class SplashMenu : MonoBehaviour {
public Texture2D PlayButton;
public Texture2D HelpButton;
public int ButtonHeight = 80;
public int ButtonWidth = 200;
void OnGUI() {
GUI.DrawTexture (new Rect(Screen.width * .5f, Screen.height *.5f, Screen.width *.5f, Screen.height * .1f), PlayButton);
}
}
This is working to show the buttons:
public class SplashMenu : MonoBehaviour {
public Texture2D PlayButton;
public Texture2D HelpButton;
public float ButtonHeight = 80;
public float ButtonWidth = 200;
public float ButtonX = Screen.width * .5f;
public float ButtonY = Screen.height * .5f;
void OnGUI() {
GUI.DrawTexture (new Rect(ButtonX, ButtonY, ButtonWidth, ButtonHeight), PlayButton);
GUI.DrawTexture (new Rect(ButtonX, ButtonY + ButtonHeight, ButtonWidth, ButtonHeight), HelpButton);
}
}
However, when I add in the event checker, I get this error:
public class SplashMenu : MonoBehaviour {
public Texture2D PlayButton;
public Texture2D HelpButton;
public float ButtonHeight = 80;
public float ButtonWidth = 200;
public float ButtonX = Screen.width * .5f;
public float ButtonY = Screen.height * .5f;
// Draw something in the boxes
void OnGUI() {
Rect Button1 = new Rect(ButtonX, ButtonY, ButtonWidth, ButtonHeight);
Rect Button2 = new Rect(ButtonX, ButtonY + ButtonHeight, ButtonWidth, ButtonHeight);
GUI.DrawTexture (Button1, PlayButton);
GUI.DrawTexture (Button2, HelpButton);
}
void Update() {
// Check for clickage
if (Input.GetMouseButton(0))
{
if(Button1.Contains(Event.current.mousePosition))
{
Debug.Log ("Mouse in Button1");
}
}
}