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 /
avatar image
1
Question by Wolf12 · Jul 16, 2013 at 05:13 PM · level-designkey pressedgame save

How can I make the level restart when someone presses R

Okay, so in my game if you fall out of the world, you continue to fall for ever, I want to make it so you can press R when you fall out to restart something that triggers Application.LoadLeve(1); Ive googled all over the place for this answer could not find it how would I make it detect a keyboard press?

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
7
Best Answer

Answer by amphoterik · Jul 16, 2013 at 05:14 PM

You will do something like:

 void Update()
 {
     if(Input.GetKeyDown(KeyCode.R))
         Application.LoadLevel(0); //or whatever number your scene is
 
 }

More info on the GetKeyDown method can be found here: http://docs.unity3d.com/Documentation/ScriptReference/Input.GetKeyDown.html

Comment
Add comment · Show 9 · 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 Wolf12 · Jul 16, 2013 at 05:59 PM 0
Share

So where would I put this javascript? anywhere?

avatar image robertbu · Jul 16, 2013 at 07:12 PM 1
Share

@Wolf12 - Please don't open a new question when comments to existing questions don't get answered fast enough. The above code is C# Create a new C# script and replace the Update() function in that script with the text posted by @amphoterik. Drag and drop it on any object in the scene.

avatar image amphoterik · Jul 17, 2013 at 12:50 AM 0
Share

@Wolf12 if this answered your question be sure to mark it as the answer. It helps future readers and gives you karma.

avatar image Wolf12 · Jul 17, 2013 at 03:29 AM 0
Share

Sorry amphoterik, It did not work, I get a parsing error still

avatar image Wolf12 · Jul 17, 2013 at 03:31 AM 0
Share

Heres a screenshot of the error http://vvcap.net/db/5fUXhj$$anonymous$$$$anonymous$$T-1w-$$anonymous$$t4nD0i.htp

Show more comments
avatar image
0

Answer by zotey · Jul 16, 2013 at 05:20 PM

Hey,

check this.

Zotey

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 amphoterik · Jul 16, 2013 at 05:21 PM 1
Share

It is a good idea to give more information in your answer than just a link. This is especially true because the link could eventually break.

avatar image
0

Answer by Dimling · Jul 17, 2013 at 06:01 AM

This is how the code should look like. (maybe with a little "R" in Restart to make it work with your script, but should have been with a capital one) ;)

 public class Restart : MonoBehaviour{
     void Update(){
         if(Input.GetKeyDown(KeyCode.R)){
             Application.LoadLevel(1); 
         }
     }
 }

Maybe you should read some more about basic scripting: http://unity3d.com/learn/tutorials/modules/beginner/scripting

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 recnepsgames · Nov 21, 2015 at 03:20 PM 0
Share

@Dimling thank I'm using this in my game it works very well

avatar image meat5000 ♦ recnepsgames · Nov 21, 2015 at 03:29 PM 0
Share

Give thanks with a +1 ;)

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

21 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

Related Questions

Changes to one map affect another. Help?! 1 Answer

Open World In Unity 0 Answers

Massive Open world, is modular a good idea. 1 Answer

Attempting open world design, have read about streaming assets, is there a good example or open project I could download to really get a good idea how it works? 0 Answers

How to load levels with colliders? 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