Detect Mouse Click on GUI Texture (NOT ONGUI)

Hi everyone, I am new to Unity, and Unity Answers.

I am creating a stat selection screen for homework.
I am confused about writing a line of code that is probably very simple.
I want to detect a click on the GUI Texture without using on Gui if its possible. :slight_smile:

I have searched for the post that can help me but I do not think anyone is in my situation.

I hope somebody can help! :slight_smile:
Thanks for your time.

using UnityEngine;
using System.Collections;

public class StatScript : MonoBehaviour {
	private int[] stats = new int[] {5,5,5,5,5,5};
	private int pointSpend = 25; 
	public GUIText points;

	public GUIText strength;
	public GUITexture strengthSpend;
	public GUITexture strengthReturn;

	public GUIText stamina;
	public GUITexture staminaSpend;
	public GUITexture staminaReturn;

	public GUIText constitution;
	public GUITexture constitutionSpend;
	public GUITexture constitutionReturn;

	public GUIText agility;
	public GUITexture agilitySpend;
	public GUITexture agilityReturn;

	public GUIText intellegence;
	public GUITexture intelligenceSpend;
	public GUITexture intellegenceReturn;

	public GUIText willpower; 
	public GUITexture willpowerSpend;
	public GUITexture willpowerReturn;

	public AudioClip selectTone;


	// Update is called once per frame
	void Update () {
				points.text = pointSpend.ToString (); 
				strength.text = stats [0].ToString ();
				stamina.text = stats [1].ToString ();
				constitution.text = stats [2].ToString ();
				agility.text = stats [3].ToString ();
				intellegence.text = stats [4].ToString ();
				willpower.text = stats [5].ToString ();

		}

	void OnMouseUp(){
		audio.PlayOneShot (selectTone);

		if (strengthSpend)){
			stats[0]= stats[0] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (strengthReturn){
			stats[0]= stats[0] -1;
			pointSpend = pointSpend +1; 
		}

		else if  (staminaSpend){
			stats[1]= stats[1] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (staminaReturn){
			stats[1]= stats[1] -1;
			pointSpend = pointSpend +1;
		}

		else if  (constitutionSpend){
			stats[2]= stats[2] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (constitutionReturn){
			stats[2]= stats[2] -1;
			pointSpend = pointSpend +1; 
		}

		else if  (agilitySpend){
			stats[3]= stats[3] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (agilityReturn){
			stats[3]= stats[3] -1;
			pointSpend = pointSpend +1; 
		}

		else if  (intelligenceSpend){
			stats[4]= stats[4] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (intellegenceReturn){
			stats[4]= stats[4] -1;
			pointSpend = pointSpend +1; 
		}

		else if  (willpowerSpend){
			stats[5]= stats[5] +1;
			pointSpend = pointSpend -1; 
		}

		else if  (willpowerReturn){
			stats[5]= stats[5] -1;
			pointSpend = pointSpend +1; 
		}
	}	
}

You can use GUITexture.HitTest(). This function takes a screen position. So for example if you wanted to test if โ€˜staminaReturnโ€™ was under the mouse, you could do:

if (staminaReturn.HitTest(Input.mousePosition) {
    Debug.Log("I'm over 'Stamina Return'");
}