- Home /
Modifying the Arial material for fading GUITexts
Seems like a really simple problem, but I can't seem to find an answer to this after digging in Unity and searching here for a day or so.
I have a fade script that will fade the alpha of a GUIText prefab. The GUIText is using the Arial default font with NONE as the material.
public class FadeGUITexts : MonoBehaviour
{
public float fadeDuration = 1.0f;
private void Start ()
{
StartCoroutine(StartFading());
}
private IEnumerator StartFading()
{
yield return StartCoroutine(Fade(0.0f, 1.0f, fadeDuration)); // Fade in at start
//yield return StartCoroutine(Fade(1.0f, 0.0f, fadeDuration));
//Destroy(gameObject);
}
private IEnumerator Fade (float startLevel, float endLevel, float time)
{
float speed = 1.0f/time;
for (float t = 0.0f; t < 1.0; t += Time.deltaTime*speed)
{
float a = Mathf.Lerp(startLevel, endLevel, t);
guiText.font.material.color = new Color(guiText.font.material.color.r,
guiText.font.material.color.g,
guiText.font.material.color.b, a);
yield return 0;
}
}
This fade script works beautifully, but the problem I am having is that ALL the GUITexts in the scene are fading at the same time because I'm modifying the alpha on the single GUIText material (which is the Arial font material.)
I've tried adding other materials to each GUIText prefab, but anything other than NONE turns the font into gibberish. I don't see any option in the material browser to select the actual ARIAL material or texture for modification.
So, is the Arial font material accessible in some way? Or would I be better served using a different font that generates it's own materials/textures?
Or am I just doing this wrong and shouldn't be trying to modify the material.color directly?
Thanks in advance!
Answer by Eric5h5 · Oct 16, 2011 at 01:39 AM
Use guiText.material instead. That way it will make a unique material for each GUIText at runtime, and not touch the actual font asset.
That did it! $$anonymous$$any thanks!
I tried to upvote your answer, but the site won't let me yet (for some unknown reason)
Your answer
Follow this Question
Related Questions
How do I get the current alpha value of a material? 2 Answers
Text not reverting back to original properties after gameplay 1 Answer
Changing font material alpha for just one clone 0 Answers
Material alpha is 1 but still see through 0 Answers
Editing the alpha of one GUItext edits the alpha of them all 1 Answer