Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
This question was closed Jan 23, 2015 at 12:55 PM by meat5000 for the following reason:

Duplicate Question

avatar image
0
Question by KnightRiderGuy · Jan 23, 2015 at 12:21 PM · c#waitforsecondsdelayloadlevel

C# Load Level after seconds

Here is another C# issue that seemed to be easier in java, my code guy likes C# so I have been trying to save him a lot of time converting what I can to C#, I have tried looking this up but I keep finding these long over complicated methods to do something I believe should be quite simple. Anyways all I basically want to do is ad a slight delay in my C# script so the level will load after a short second or so. This is my very simple next level load code which works, just works too fast ;)

 using UnityEngine;
 using System.Collections;
 
 public class SCBlueButton : MonoBehaviour {
     
     
     public void  ModeSelect(){
         Application.LoadLevel("SurveillanceModeSelectScreen");
     }
 }
Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Negatiw · Nov 08, 2016 at 11:41 AM 0
Share

I do believe there is a simple solution to your problem. I don't know if you still try to solve it in a more simple way, but here is my solution for this:

 >     > using UnityEngine;  using
 >     > System.Collections;    public class
 >     > SCBlueButton : $$anonymous$$onoBehaviour {
 >     > 
 >     >  private float waitForSeconds;     
 >     > 
 >     > void Start(){
 >     > 
 >     >               Invoke("$$anonymous$$odeSelect", waitForSeconds);
 >     > 
 >     > }
 >     > 
 >     >      public void  $$anonymous$$odeSelect(){
 >     >          Application.LoadLevel("Surveillance$$anonymous$$odeSelectScreen");
 >     >      }  }




2 Replies

  • Sort: 
avatar image
8
Best Answer

Answer by shriya · Jan 23, 2015 at 12:29 PM

hi

Use below mentioned code

  using UnityEngine;
  using System.Collections;
  
  public class SCBlueButton : MonoBehaviour {
      
      
      public void  ModeSelect(){
         StartCoroutine("Wait");
         
      }
 
 IEnumerator Wait()
 {
   yield return new WaitForSeconds(2);
 

 Application.LoadLevel("SurveillanceModeSelectScreen");
     }
      }

2 can be changed to any value i.e the specific amount of time you want to wait before loading level.

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image HarshadK · Jan 23, 2015 at 12:31 PM 1
Share

This code will still load the level immediately. The line

 Application.LoadLevel("Surveillance$$anonymous$$odeSelectScreen");

should be inside coroutine below yield statement.

   using UnityEngine;
   using System.Collections;
   
   public class SCBlueButton : $$anonymous$$onoBehaviour {
       
       
       public void  $$anonymous$$odeSelect(){
          StartCoroutine("Wait");
       }
  
  IEnumerator Wait()
  {
    yield return new WaitForSeconds(2);
           Application.LoadLevel("Surveillance$$anonymous$$odeSelectScreen");
  }
   }
avatar image KnightRiderGuy · Jan 23, 2015 at 12:47 PM 1
Share

I ended up figuring it out after some additional googling but yup, that was it. $$anonymous$$ine looks a tiny bit different but the idea is basically the same, thanks Harshad$$anonymous$$ :)

 using UnityEngine;
 using System.Collections;
 
 public class SCBlueButton : $$anonymous$$onoBehaviour {
     
     
     public void  $$anonymous$$odeSelect(){
         StartCoroutine(LoadAfterDelay("Surveillance$$anonymous$$odeSelectScreen"));
     }
         
     IEnumerator LoadAfterDelay(string levelName){
         yield return new WaitForSeconds(01); // wait 1 seconds
         Application.LoadLevel(levelName);
     
     }
 }
avatar image Light_ · Jul 08, 2016 at 12:29 AM 0
Share

I am trying to get a video to play, so like remember if you were idle at a NES game for about a $$anonymous$$ute then a video story would run. I have an object with a movie material in the scene and after some time I'd like it to change to active (overtake camera view< I got that) and then start playing.

 public void Play$$anonymous$$ovie()
     {
         StartCoroutine("Wait");
     }
 
             IEnumerator Wait()
     {
         yield return new WaitForSeconds (01f);
         movie.SetActive (true);
         GetComponent<Renderer> ().material.mainTexture = sS$$anonymous$$ain$$anonymous$$enu;
         sS$$anonymous$$ain$$anonymous$$enu.Play ();


the object with the movie material is set to "not active" by default. I got this to work with a pause menu, but trying this with a movie on a timer isnt' working lol. Any ideas?

avatar image
0

Answer by ramp · Jan 23, 2015 at 12:34 PM

Hello,

In C#,you can use code like this.

IEnumerator LoadAfterWait(string levelName)

{

yield return new WaitForSeconds(2f); // wait 2 seconds

Application.LoadLevel(levelName);

}

And you must start the coroutine like this:

StartCoroutine(LoadAfterWait("SurveillanceModeSelectScreen"));

Thanks

Ram

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image KnightRiderGuy · Jan 23, 2015 at 12:54 PM 0
Share

Thanks, I suppose my only other question would be for how to make the time about half a second?

avatar image ahmadi9112 · Feb 19, 2015 at 06:43 PM 0
Share

hi you shriya . tank you so much. cz your code work in my project.

avatar image damien123 · Jul 12, 2016 at 08:13 AM 0
Share

it doesnt work (unity 5?)

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

WaitForSeconds load level delay not working 1 Answer

Csharp: how to make script wait for x seconds 3 Answers

Run script when level begins? 1 Answer

C# simple delay execution without coroutine? 2 Answers

Can IEnumerator be called more than once? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges