Changing Text Mesh color

using UnityEngine;
using System.Collections;

public class Button : MonoBehaviour {

	public TextMesh textmesh;
	public Material normally;
	public Material onMouseHover;
	public AudioClip hover_sound;
	public bool quit = false;



	// Use this for initialization
	void Start () {

	
	}
	
	// Update is called once per frame
	void Update () {

		RaycastHit HitInfo;
		bool played_sound = false;

		if(Physics.Raycast(Camera.main.ScreenPointToRay(Input.mousePosition) , out HitInfo))
		   {

			textmesh.color = Color.gray;
			if(!played_sound)
			{

				played_sound = true;
				audio.Play();


			}

		

		   }else{

			textmesh.color = Color.white;
			played_sound = false;
		}
	
	}
	void onMouseEnter() {

	
	
		Debug.Log("Works!");


	}
	void onMouseDown()
	{

	if(quit)

		{



			Application.Quit ();
		}



	}
}

Hi
I am fairly new to unity. Soo i am trying to create a 3d menu and i have this script that changes the color whenever mouse hovers over one of the buttons. The problem is when one of the buttons gets triggered all of them change color.
Thanks for the replies:)

To use mouse event functions(OnMouseEnter, …) need a Collider.

To change TextMesh color, change color TextMesh attribute.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(BoxCollider))]
[RequireComponent(typeof(TextMesh))]
public class ButtonTextMesh : MonoBehaviour {   

    public Color normallyColor = Color.white;
    public Color mouseHoverColor = Color.red;
    public bool quit = true;

    TextMesh textmesh;
   
    void Start(){

        textmesh = GetComponent<TextMesh>();
        textmesh.color = normallyColor;
   
    }

    void OnMouseEnter(){ textmesh.color = mouseHoverColor; }
    void OnMouseExit() { textmesh.color = normallyColor; }
    void OnMouseDown() { if(quit) Debug.Log("Quit"); }
   
}

Download link.

Already figured it out thanks though:))

Can you please post your solution? :slight_smile: