- Home /
Question by
autumnandaaron · Mar 31, 2019 at 06:49 PM ·
uionmouseover
UI OnMouseOver for specific objects
This may be obvious, but I'm a beginner. I have this code that I would like to apply to multiple objects to display text whenever I hover the mouse over them. The problem is that, even though the different messages will display, they will only display over one object, instead of the other objects I applied the script to.
void Start()
{
myText = GameObject.Find("Text").GetComponent<Text>();
myText.color = Color.clear;
}
void Update()
{
FadeText();
}
private void OnMouseOver()
{
displayInfo = true;
}
private void OnMouseExit()
{
displayInfo = false;
}
void FadeText()
{
if (displayInfo)
{
myText.text = myString;
myText.color = Color.Lerp(myText.color,Color.white, fadeTime*Time.deltaTime);
}
else
{
myText.color = Color.Lerp(myText.color, Color.clear, fadeTime * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
Bend Image/Filled Image detect mouse enter/exit 1 Answer
Illuminating a 3D object's edges OnMouseOver (script in c#)? 1 Answer
OnMouseHover on UI 1 Answer
On Pointer Enter for semi-transparent UI? 2 Answers
Help with an upgrade tower system 0 Answers