[Solved]MouseEnter not working!

When my mouse is over text, it should change it’s color. I made a script (copied from the OnMouseEnter() documentation) but it just won’t work. I attached a Collider to my Text.
The following code is not working:
using UnityEngine;
using System.Collections;

public class TextHandler : MonoBehaviour {

	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
	
	}
	 void OnMouseEnter() {
        renderer.material.color = Color.red;
    }
}

What did I do wrong?

1 Answer

1

GUITexts don’t need colliders. Also, you need to be changing the font colour, not the renderer, as it’s not a standard 3D object material. From the top of my head:

guiText.material.font.color = Color.red;

It's a 3d text gameobject, not GUIText. I found the problem: a collider was blocking the text!

–