- Home /
my co-routine isn't running when i tell it to
i need help with this, because for some weird reason, my startup coroutine doesnt run. i know this because i temporarily added a debug.log as the first thing the coroutine does, but it didnt show up in the console.
void Start()
{
rb = GetComponent<Rigidbody>();
GameObject.Find("PauseMenuManager").GetComponent<MenuController_Paused>().isPaused = false;
Time.timeScale = 1;
StartCoroutine(startup());
}
IEnumerator startup()
{
Camera.GetAllCameras(camerasinscene);
while (GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Bloom>().bloomIntensity > 0)
{
yield return new WaitForSeconds(0.00000001f);
GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Bloom>().bloomIntensity = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Bloom>().bloomIntensity - 1;
}
foreach (var cam in camerasinscene)
{
cam.GetComponent<Bloom>().bloomIntensity = GameObject.FindGameObjectWithTag("MainCamera").GetComponent<Bloom>().bloomIntensity = 0;
}
}
Add a debug statement to Start() to verify that is being called correctly. I would suspect that either the object doesn't exist or is disabled/being disabled.
Also cache the main cameras bloom object. It's inefficient and unnecessary to make so many calls to FindGameObjectWithTag and GetComponent when it just returns the same result anyway, and makes your code harder to read.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Rotate an object using Quaternion.RotateTowards() inside a Coroutine? 1 Answer
How do i make sure an Object is initialized before using it ? C# 2 Answers
In coroutin function,if(x) { yield return a } . if(y) { yield return b }. Is it possible? 0 Answers