- Home /
Changing Gui Text on mouse over not working for black text
void OnMouseEnter()
{
guiText.material.color = Color.green;
}
void OnMouseExit()
{
guiText.material.color = Color.black;
}
The above is code that I have for changing the color of my guiText on a mouse over.
My GUIText is initially set to black (0,0,0,255). However, this will not change the text to green on mouse over.
However, if I start with the text being White instead of Black, the above code works just how I want it. It even sets it to black on mouseExit and continues to work by going back to green on mouseEnter
Answer by robertbu · May 06, 2014 at 06:50 PM
Try:
guiText.color = Color.black;
I.e. don't use 'material'.
Answer by Asthegor · Oct 23, 2014 at 09:21 PM
There is a better solution to change color of a GUIText :
public class OptionController : MonoBehaviour
{
public Color myColor;
public GUIText myGUIText;
void OnGUI ()
{
//everyone do this for the first time :
myGUIText.guiText.color = myColor;
// but it SEEMS it doesn't work !!!!!!
// the line below work perfectly :
myGUItext.guiText.color = new Color(myColor.r, myColor.g, myColor.b, 1);
// MIRACLE !!! The color of your GUIText has been changed (^_^)
}
The issue came from the Color function. The alpha value is, by default, not set. So, the value is 0. The alpha means the transparency of the text.
Your answer
![](https://koobas.hobune.stream/wayback/20220613144412im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Simple menu problem 2 Answers
How to detect Mouse Events when the object is coverd by another object? 1 Answer
GUItext works 1 of 3 situations? 0 Answers
Draw GuiText on 2d tile sprite Like 2048 game 0 Answers
Display GUI Text 1 Answer