- Home /
GUIText not firing OnMouseOver
Hello, I'm using Unity since a week in the 2D mode.
I'm trying to add mouse event listeners for a GUIText. I've attached a script to each GUIText in my scene but that doesn't seem to work...
Do you have any idea ?
*I've included my C# script and a screen capture of the actual setup in unity.
using UnityEngine;
using System.Collections;
public class HUDItemController : MonoBehaviour
{
void OnMouseOver () {
Debug.Log ("mo");
}
void OnMouseUp () {
Debug.Log ("mu");
}
void OnMouseEnter () {
Debug.Log ("me");
}
}
Answer by Igneom · Sep 23, 2014 at 12:26 AM
It works on my end, but I made some quick changes to effectively demonstrate that.
bool over, up, enter;
void OnMouseOver()
{
if (!over)
{
Debug.Log("mo");
over = true;
}
}
void OnMouseUp()
{
if (!up)
{
Debug.Log("mu");
up = true;
}
}
void OnMouseEnter()
{
if (!enter)
{
Debug.Log("me");
enter = true;
}
}
If you test this code, you will see that it works, your problem was that the OnMouseOver() was spamming the console and you were not able to see when it showed the other states.
Thank you for the quick answer. It was probably a bug in unity because after restarting the problem was resolved, whitout changing anything.
GUItext
normally doesn't need a collider for this.
Happy coding.
Your answer
Follow this Question
Related Questions
What does a quad look like? 1 Answer
How to add event to an object 1 Answer
Checking if a gameobjects active in your heirarchy. 2 Answers
2D Animation does not start 1 Answer