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
5
Question by LiamDietrich · Oct 09, 2016 at 07:48 AM · restart game

How to restart the game

I am looking for a way that I can restart the game with pressing the letter R without closing out of the application in standalone. I only have 1 scene and I have NO Experience. Please help me:D

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 LiamDietrich · Oct 09, 2016 at 11:13 PM 0
Share

@doublemax Alright... It does not really make sense. IS there any way I could make the scene restart when my character (Skycar) hits a plane?

4 Replies

· Add your reply
  • Sort: 
avatar image
11

Answer by doublemax · Oct 09, 2016 at 07:52 AM

 using UnityEngine.SceneManagement;

 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 Steven-1 · Apr 20, 2020 at 02:30 PM 1
Share

this doesn't work when you have objects marked as dontdestroyonload

avatar image
1

Answer by LiamDietrich · Oct 09, 2016 at 03:24 PM

@doublemax where do you put this line on code?

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 doublemax · Oct 09, 2016 at 03:29 PM 1
Share

Save this as "Restart.cs" and add it to any component that's always active, e.g. the main Camera or a Game$$anonymous$$anager object if you have something like that.

 using UnityEngine;
 using UnityEngine.Scene$$anonymous$$anagement;
 
 public class Restart : $$anonymous$$onoBehaviour
 {
   void Update ()
   {
     if( Input.Get$$anonymous$$eyDown($$anonymous$$eyCode.R) )
     {
       Scene$$anonymous$$anager.LoadScene( Scene$$anonymous$$anager.GetActiveScene().name );
     }
   }
 }
avatar image
0

Answer by NikitaDemidov · Dec 31, 2018 at 03:00 PM

using UnityEngine;

public class Restart : MonoBehaviour {

 void Start()
 {

 }

 void Update()
     {
         if (Input.GetKeyDown(KeyCode.R))
         {
             Application.LoadLevel(0);
         }
     }
 }


Try this!

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 vfxjex · Oct 28, 2019 at 12:33 PM 1
Share

I believe this should be the proper code in restarting your game as Application.LoadLevel(0); gets the first scene of your game while the Scene$$anonymous$$anager.GetActiveScene().name could probably gets the third level of your game which does not totally restart your game but just restarting that level. However the Code is obsolete and rather use Scene$$anonymous$$anager.LoadScene(0);

avatar image
0

Answer by cmdbarret · Dec 31, 2018 at 03:39 AM

@doublemax can I ask why this changes the games lighting?

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 doublemax · Dec 31, 2018 at 01:31 PM 0
Share

I haven't used Unity for 2 years, but Googling found this: https://answers.unity.com/questions/1264278/unity-5-directional-light-problem-please-help.html

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

8 People are following this question.

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

Related Questions

??Whats wrong with this script??? HELP 2 Answers

Darker Level when Player Respawn 1 Answer

Simple Restart not working 0 Answers

Is there a way to return all your viaraibles and script to the way it was when the game started 0 Answers

Reset Transform.position 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