this script i place it in the same scene of my game… but sometimes the coroutine for begining screen finish first before the coroutine for get version because the get version need a connection to webserver, and sometime the web server is lagging…
so how can i make the get version coroutine finish first and after that begining screen can start…
Since you have 2 scripts a solution could be to have each script manage their own coroutine and turning the coroutine off is controlled via accessing a function.
Note that in order for stopcoroutine to work you must start the coroutine using a string name of the IEnumerator. EX:
An example of how to do what i have just described…
Script A
private bool coroutineRunning = false;
void Start(){
coroutineRunning = true;
StartCoroutine("MyCoroutine");
Debug.Log("Coroutine Started");
}
public void StopTheCoroutine(){
if(coroutineRunning){
coroutineRunning = false;
Debug.Log("Stopping the coroutine");
StopCoroutine("MyCoroutine");
}
}
IEnumerator MyCoroutine(){
yield return new WaitForSeconds(10.0f);
Debug.Log("Coroutine has elapsed");
coroutineRunning = false;
}
Script B
void StopTheCoroutineOnScriptA(){
scriptA.StopTheCoroutine();
Debug.Log("Script B has stopped Script A's coroutine");
}
The above will stop the coroutine running dead in its tracks. If you are trying to wait for the coroutine to finish before starting another:
By utilizing a method the user Tetrad has described in another question, you can use “while” loops to wait for the other coroutine to end. An example from that question is posted below as well as a link
Tetrad ~
IEnumerator DragObject( stuff )
{
// setup stuff
while( Input.GetMouseButton( 0 ) )
{
// update position stuff
yield return null; // returning null is faster than returning 0
}
//done with dragging stuff
}