Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
avatar image
0
Question by terchilaionutgeorge · Feb 27, 2019 at 09:12 AM · restart game

How to Restart Level ?

Hello peeps! I have a problem, before the script goes, it would give restart level when it hit an object. I've made some changes and now it's not working the same way. I added tags to objects but I do not know what to do.

 private void OnTriggerEnter2D(Collider2D Respawn)
     {
         if (Respawn.tag.Equals("Respawn"))
 
         {
             StartCoroutine("ReloadScene");
             Time.timeScale = 0f;
         }
 
 
         IEnumerator ReloadScene()
         {
             yield return new WaitForSecondsRealtime(0.5f);
             SceneManager.LoadScene("SampleScene");
 
 
         }
 
     }

Comment
Add comment · Show 2
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 tormentoarmagedoom · Feb 27, 2019 at 09:42 AM 0
Share

Good day. Explain, be specifyc and clear, what you have, what you get, what you want...

Did you wrote this code?

Why are you doing this?

 Time.timeScale = 0f;

You know what it does? you are stopping internal time... Its to "stop the game" while loading ?

Where is the problem then? what is not working? what you get? what you want to get?

OR give more infor or we can not help you...

avatar image terchilaionutgeorge · Feb 27, 2019 at 09:53 AM 0
Share

Hi @tormentoarmagedoom , I did not write the code, I looked at youtube in the tutorial. So, before the main object was to say "the player" was hitting the obstacle, the game was over. Now the player gets hit by the object, nothing happens, it just gets stuck in the object. I want to resume the scene when the player hits the object. Excuse but I use google translations to express myself better.

3 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by terchilaionutgeorge · Feb 28, 2019 at 07:52 AM

SOLVED

  private void OnTriggerEnter2D(Collider2D Player)
     {
         if (Player.tag.Equals("Respawn"))
             StartCoroutine("ReloadScene");
         Time.timeScale = 0f;
     }
 
     IEnumerator ReloadScene()
     {
         yield return new WaitForSecondsRealtime(0.5f);
         SceneManager.LoadScene("SampleScene");
     }
 
Comment
Add comment · Show 1 · 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 Temseii · Feb 28, 2019 at 09:52 AM 1
Share

No need to be using a coroutine, just call the method using Unity's Invoke and handle everything within one method.

 Invoke("ReloadScene", 0.5);
avatar image
0

Answer by hydrox1 · Feb 27, 2019 at 10:10 AM

Hi, this should fix it : Application.LoadLevel(Application.loadedlevel); just replace this with the SceneManager...

Comment
Add comment · Show 1 · 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 terchilaionutgeorge · Feb 27, 2019 at 10:19 AM 0
Share

and i get this in console: Coroutine 'ReloadScene' couldn't be started! UnityEngine.$$anonymous$$onoBehaviour:StartCoroutine(String)

avatar image
0

Answer by deus0 · Jun 30, 2021 at 09:34 AM

I believe its something like:

                 UnityEngine.SceneManagement.SceneManager.LoadScene(UnityEngine.SceneManagement.SceneManager.GetActiveScene().name);
Comment
Add comment · 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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

101 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

I created a maze game where the ai uses a pathfinder to find the MainCharacter. I want when the ai touches the MainCharacter(First Person Controller), then reset the game. I have gotten help on my code a few time but the code never works. 2 Answers

My game keeps restarting at random 1 Answer

How do I restart games with more than one level 1 Answer

How reset the Position of all puzzle pieces? 1 Answer

Car Game For School Project 2 Answers


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