- Home /
 
               Question by 
               deepestPuddle · Aug 22, 2013 at 05:43 AM · 
                loadlevelwaitseconds  
              
 
              Load Level delay on collision C#
Hi,
What I am trying to do is have our player object contact another object, delay a few seconds, then load another level. I am new to Unity, coding, and this community. Below is what I have from trying to piece together things I've found around the net.
 // loads a level (scene) when player object contact is made with item
 void OnTriggerEnter(Collider Others) 
 {
     if (Others.tag == "Item")
     StartCoroutine(LoadLevel("test", 5.0f));
 }
 
 IEnumerator LoadLevel(string "test", float 5.0f)
 {
     yield return WaitForSeconds(5.0f);
     Application.LoadLevel("test");
 }
 
}
I am very grateful for any constructive feedback you may have.
               Comment
              
 
               
              Answer by robertbu · Aug 22, 2013 at 05:48 AM
Try this:
 void OnTriggerEnter(Collider Others) 
 {
     if (Others.tag == "Item")
         StartCoroutine(LoadLevel("test", 5.0f));
 }
 
 IEnumerator LoadLevel(string level, float waitTime)
 {
     yield return new WaitForSeconds(waitTime);
     Application.LoadLevel(level);
 }
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                