GUITexture Button?

Hello, how can I make something happen when my GUITexture is clicked? My GUITexture is “achieved” by this script which work’s fine btw :slight_smile: :slight_smile:

	public Texture2D background;
	int theHeight = 50;
	int theWidth = 200;
	
    void OnGUI() {
		GUI.DrawTexture(new Rect(Screen.width / 2 - (theWidth / 2), Screen.height - 50, theWidth, theHeight), background);
	}	

Thanks, Andreas :slight_smile:

Use GUI.Button() instead of GUI.DrawTexture. There are many different forms of this function. The second one is probably the one you want.

 if ( GUI.Button(new Rect(Screen.width / 2 - (theWidth / 2), Screen.height - 50, theWidth, theHeight), background)) {
    // Do something when button is pressed.
}