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
4
Question by Mrkrisher · Oct 25, 2016 at 05:34 AM · buttonresetrestartrestart game

Creating a Restart Button

Hi, I'm new to Unity, so I don't know much yet, but I've been creating a game which is filled with obstacles, and different paths, and you have to roll the ball around the whole area to collect Yellow Cubes. I'm trying to figure out how to create a Restart button, so that if the player messes up, or falls out, they can just play again. I haven't written any type of script for the restart button yet, so everybody's help is appreciated! (Currently, if you fall out of the boundaries, or want to restart, you have to close out the whole game, and start it again.)

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

3 Replies

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

Answer by JScotty · Oct 25, 2016 at 06:50 AM

Hi Mrkrisher,

First create an button UI -> Button Then create an class

C# ex:

     using UnityEngine;
     using UnityEngine.SceneManagement;
     using System.Collections;
     
     public class Restart : MonoBehaviour {
     
         public void RestartGame() {
             SceneManager.LoadScene(SceneManager.GetActiveScene().name); // loads current scene
         }
     
     }


attatch this class to a GameObject and drag it in the Button -> OnClick component Select -> Restart->RestartGame

And your scene will restart.

Hope this helps for you

NOTE: In case you are using unity 5.3 or less use Application.LoadLevel(Application.loadedLevel); instead of SceneManager.LoadScene(Application.loadedLevel);

Comment
Add comment · Show 14 · 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 Mrkrisher · Oct 25, 2016 at 09:42 PM 0
Share

Okay, well I got the button on the right position and stuff. The problem is the script won't work, I just copy and pasted your exact script, but an error message pops up. (And btw I have Version 5.3.6) alt text

avatar image JScotty Mrkrisher · Oct 27, 2016 at 06:11 AM 0
Share

What is your error message?

avatar image Mrkrisher JScotty · Oct 28, 2016 at 07:25 PM 0
Share

alt text

screen-shot-2016-10-25-at-54002-pm.png (78.4 kB)
Show more comments
avatar image aditya007 · Oct 26, 2016 at 03:55 AM 0
Share

Application.loadedlevel is Deprecated. You should use Scene$$anonymous$$anager.LoadScene(Scene$$anonymous$$anager.GetActiveScene().name) ins$$anonymous$$d.

avatar image Mrkrisher aditya007 · Oct 26, 2016 at 11:56 PM 0
Share

His script says that right? He said to use Scene$$anonymous$$anager for 5.3 or more, and I used Scene$$anonymous$$anager because i am 5.3.6

avatar image Zitoox Mrkrisher · Oct 29, 2016 at 02:09 AM 0
Share

If you are getting this error, probally you named your script from a different name than the one in the example and copied it.

avatar image Mrkrisher · Oct 29, 2016 at 05:04 PM 0
Share

Ok well, now the script attached to the empty child which I named Restart. I didn't attach it to anything else. No error message pops up, but when I enter play mode and click restart, nothing happens. @Namey5

avatar image EpicPants Mrkrisher · Oct 31, 2016 at 12:20 PM 1
Share

Have you linked the restart method to the UIButtons OnClick event? https://unity3d.com/learn/tutorials/topics/user-interface-ui/ui-button?playlist=17111

avatar image Mrkrisher · Nov 01, 2016 at 10:49 PM 0
Share

The reset works but has a $$anonymous$$or problem. Everything resets fine, but when I reset, the directional light goes away, so the screen is pretty dark. It's probably a simple solution, but its one of the last steps to completing my game. Anybody know?

And btw Thank you guys so much for helping me. @Namey5 @JScotty @EpicPants

avatar image sxnorthrop Mrkrisher · Nov 01, 2016 at 10:54 PM 1
Share

That only happens in the editor. When the game is built you won't notice it. It's just the lightmaps not being able to rebuild because you're in playmode.

avatar image Mrkrisher sxnorthrop · Nov 01, 2016 at 11:49 PM 1
Share

Thank you!

avatar image SmallLion · Dec 07, 2020 at 02:14 PM 0
Share

Thank you.Very useful.

avatar image
8

Answer by Putteli · May 03, 2017 at 07:50 AM

Hi! If anyone has problems with timeScale, after restarting. You should add Time.timeScale = 1f; after that so it will return back to normal timeScale. For Example in my game when user dies time will be paused and if i just only did restart it was still paused.

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 EvanCheddar · Mar 13, 2018 at 06:09 PM 0
Share

good call @Putteli, thank you

avatar image youssefelbouzai · Sep 22, 2018 at 12:22 PM 0
Share

Thank you so much it helps a lot

avatar image
0

Answer by mayankela21 · Dec 03, 2020 at 12:27 PM

Use That Is More Easier

 SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex);

For Reastart

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 xPro-Gamerx · Jul 27, 2021 at 10:57 AM 0
Share

thanks bro

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

19 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

Related Questions

Simple Restart not working 0 Answers

i have a button to restart the same scene but it dont works (with images) 7 Answers

1 Scene game|| Reset variables 1 Answer

Restarting The Game error 0 Answers

,Restart Scene after level Completion 0 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