Hi there I have a simple fade in and out script for GUIText. It fades in and out then destroys itself. However it affects all GUI text in the entire game? Even though they are in different scenes. This script was attached to GUIText that I want to fade in and out and not attached to anything else. but still affects others. If I leave a scene half faded the other GUI Text in game will also be half faded. Please advise thank you.
using System.Collections;
using UnityEngine;
public class FadeInOutText : MonoBehaviour
{
public float fadeDuration = 3.0f;
private void Start ()
{
StartCoroutine (StartFading ());
}
private IEnumerator StartFading ()
{
yield return StartCoroutine (Fade (0.0f, 1.0f, fadeDuration));
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;
}
}
}