I’m trying to connect the coroutine of this script from another one. So I learned that I need to change the IEnumerator Fade to public static. Now it just spawned another error. I looked for answers and I can only find get.component solutions but I think that it will not work in Fade
Here is the script. Early thank you so much for helping me.
GameObject Player;
public string SceneName;
public float secBeforeFade = 3.0f;
public float fadeTime = 5.0f;
public Texture fadeTexture;
private bool fadeIn = false;
private float tempTime;
private float time = 0.0f;
void Start ()
{
Player = GameObject.Find ("Player");
}
public static IEnumerator Fade()
{
yield return new WaitForSeconds(secBeforeFade);
fadeIn = true;
}
void Update()
{
if (fadeIn)
{
if (time < fadeTime) time += Time.deltaTime;
tempTime = Mathf.InverseLerp(0.0f, fadeTime, time);
}
if (tempTime >= 1.0f)
SceneManager.LoadScene(SceneName);
}
void OnTriggerEnter (Collider col)
{
if (col.tag == "Player")
{
StartCoroutine(Fade());
}
}
void OnGUI()
{
if (fadeIn)
{
Color colorT = GUI.color;
colorT.a = tempTime;
GUI.color = colorT;
GUI.DrawTexture(new Rect(0, 0, Screen.width, Screen.height), fadeTexture);
}
}
}