Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 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
3
Question by Raymond 2 · Feb 09, 2011 at 06:22 PM · scenereload

Reload scene when dead

What i want is that when life is zero, that the scene just restarts, but i can't find out how to do this

i now have something like this:

var playerLife = 100;

if (playerLife < 1){ //Reload scene }

Comment
Add comment
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

5 Replies

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

Answer by Jessy · Feb 09, 2011 at 06:26 PM

http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html

http://unity3d.com/support/documentation/ScriptReference/Application-loadedLevel.html

if (playerLife < 1) Application.LoadLevel(Application.loadedLevel);
Comment
Add comment · Show 2 · 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 Raymond 2 · Feb 09, 2011 at 06:29 PM 0
Share

Thats not really working, but it doesn't show any errors so i can't see what's wrong..

avatar image Raymond 2 · Feb 09, 2011 at 06:31 PM 0
Share

Never $$anonymous$$d, solved it already, had to put a function update around it

avatar image
19

Answer by ArtOfWarfare · Dec 09, 2015 at 04:20 AM

Application.LoadLevel() is now obsolete, so you should use SceneManager.LoadScene() instead. You can pass in an argument of SceneManager.GetActiveScene() to just reload the current scene.

Note that unlike the Application class, the SceneManager class is not directly in UnityEngine, so you'll need to add this line to your imports at the top of your source file: using UnityEngine.SceneManagement;.

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 kevinrocks_786 · Dec 09, 2015 at 04:26 AM 0
Share

can you help me out: http://answers.unity3d.com/questions/1109497/unity-53-how-to-load-current-level.html

avatar image
16

Answer by lolmaster2 · Jan 23, 2017 at 08:35 AM

In Unity 5.0 and later

 // place this at the top of your file
 using UnityEngine.SceneManagement;

 // then call this to restart game
 void hardRestartGame() {
     SceneManager.LoadScene(SceneManager.GetActiveScene().name);
 }
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 Velootzs · Sep 06, 2018 at 08:26 PM 0
Share

Because the scene gets dark

avatar image
0

Answer by RealEfrain12 · Nov 24, 2020 at 04:30 AM

Unity 2019.4 Edit: This is C# Edit 2: also have the script named "TriggerControl" otherwise it's gonna give you an error This is really late but I just want to post this, put this script in to the object that you want to reload the scene when the player and the object collide, make sure the player or the object have a rigidbody.

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.SceneManagement;
 
 public class TriggerControl : MonoBehaviour
 {
    private void OnCollisionEnter(Collision other)
    {
         if (other.gameObject.tag == "Player")
         SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
    }
 }
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
avatar image
0

Answer by LeHombreDeZbragl · Feb 01, 2021 at 10:10 PM

I had this problem too. I wanted to destroy the player object and than restart the scene, but then i realized, that i was calling the code from object that was already destroyed. So just create empty object and attach the code to it. Hope this might help someone :)

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

9 People are following this question.

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

Related Questions

After scene reload script stopped working. 1 Answer

when i load scene, it starts same scene over 0 Answers

GameManager and scene design issue. 1 Answer

Problem with Application.Loadedlevel 0 Answers

MissingReference When Reloading Scene 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