Hello!
I have been trying for about 2 hours now to fix this issue. When I click on my object it creates an instantiated object with TMP Text as a child (Prefab). When I try to change the color of this text, I cannot find a way to do it, it just stays white. In this particular attempted solution I tried to put a script on the TMP object itself but the text color will not change no matter what I try.
P.S: The console will run (“Setting color to yellow”) thousands of times in a row.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class ClickTextColorScript : MonoBehaviour
{
public bool IsYellow;
private TMP_Text textMeshProC;
void Start()
{
textMeshProC = GetComponent<TMP_Text>();
}
void Update()
{
if (textMeshProC == null)
{
Debug.LogError("TMP Error");
return;
}
Debug.Log("IsYellow: " + IsYellow);
if (IsYellow)
{
Debug.Log("Setting color to yellow");
textMeshProC.faceColor = Color.yellow;
textMeshProC.color = Color.yellow;
}
else
{
Debug.Log("Setting color to white");
textMeshProC.faceColor = Color.white;
textMeshProC.color = Color.white;
}
}
}