Hi there!
In my application I want to change a scene on collision, have the player in that scene for ±20 seconds and then change the scene again.
The problem I am having is that the scene only changes the first time around and does not change to the third scene.
The code I am using is the following:
public float delay = 10;
public float delay2 = 4;
public string NewLevel = "AccidentScene";
public string NewLevel2 = "AfterActionAccident";
void OnCollisionEnter(Collision collision)
{
if (collision.gameObject.tag == "car")
{
UnityEngine.AI.NavMeshAgent agent = Car.GetComponent<UnityEngine.AI.NavMeshAgent>();
agent.isStopped = true;
StartCoroutine(LoadLevelAfterDelay(delay));
IEnumerator LoadLevelAfterDelay(float delay)
{
yield return new WaitForSeconds(delay);
SceneManager.LoadScene(NewLevel);
StartCoroutine(LoadLevelAfterDelay2(delay2));
}
IEnumerator LoadLevelAfterDelay2(float delay2)
{
yield return new WaitForSeconds(delay2);
SceneManager.LoadScene(NewLevel2);
}
}
So the first load level works, but the second one doesn’t, why is this?
I am not very good with coding so I might be missing something basic ![]()
thanks ![]()