I am currently working on a game in Unity and I have the following problem:
I have a gameobject (a Panel) and on this panel I have multiple TextMeshProUGUI displaying "Save", "Load", "Options" and "Quit". I want to make it so, that when the player hovers with the mouse over one of these objects, the fontcolor changes or the glow goes up. However, I am unable to get a hold of how to actually make it happen. Whenever I start the game the console prints all the logs even bevore I have hovered over the objects. And when I do it afterwards, the logs are not printed anymore.
So far I have the following code:
public class OptionsHoverSkript : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
OnMouseEnter();
OnMouseExit();
}
// Update is called once per frame
void Update()
{
}
private void OnMouseEnter()
{
// Get the game object.
GameObject[] initialColorText = GameObject.FindGameObjectsWithTag("HoverText");
foreach (var texts in initialColorText)
{
// Get the TextMeschProUGUI component from the object.
TextMeshProUGUI newColorText = texts.GetComponent<TextMeshProUGUI>();
string anotherText = newColorText.text;
if (anotherText == "Save")
{
Debug.Log("Log1111111111111");
}
else if (anotherText == "Load")
{
Debug.Log("Log222222222");
}
}
// Make it glow.
// newColorText.fontSharedMaterial.SetColor(ShaderUtilities.ID_GlowColor, new Color32(215, 127, 60, 255));
}
private void OnMouseExit()
{
Debug.Log("ARGH / ANGRY ARNOLD VOICE!!");
}