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 leoxs · Aug 02, 2014 at 03:17 PM · keycode

press key to continue, unity freezes

Sorry, I'm maybe too noob, but I'm making a game, and I want that when the player gets the objetive, it display something like "press space to continue" but when I get the objetive,unity freezes. Maybe I'm doing something too wrong, I don't know, this is the code fragment with the error.

 winText.text="You Win! You time is: "+finalTime+" space to continue";
             while(true){
                 if(Input.GetKey(KeyCode.Space))
                    {
                     Application.LoadLevel(Application.loadedLevel+1);
                 }
             }

Maybe the while(true) is bad? I need to make a coroutine? I'm not too good with that yet. Thanks, sorry if my english is bad.

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 ShadyProductions · Aug 02, 2014 at 03:18 PM 0
Share

Just get rid of the while loop, what do you need it for? and you need to specify which level to load you can't just do loadedLevel+1 you have to specify your scene like: Application.LoadLevel(NextScene);

avatar image robertbu · Aug 02, 2014 at 03:19 PM 0
Share

Yes the 'while(true)' is bad and is what is hanging up your app. I don't know where you have this code, or in what language (C# or Javascript). You can either place the Input.Get$$anonymous$$ey() code in Update(), or you can make the above code a coroutine and yield. But without more code and the language it is written in, I cannot be specific.

1 Reply

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

Answer by smallbit · Aug 02, 2014 at 03:21 PM

Yes its while true ...

set up a boolean to flag if player gets the "objective" (set gotObjective = true; when player finishes level) and than in update check the key.

 bool gotObjective = false;
 
 void Update()
 {
     if(gotObjective)
     {
         if(Input.GetKey(KeyCode.Space))
         {
             Application.LoadLevel(Application.loadedLevel+1);
         }
     }
 }
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 leoxs · Aug 02, 2014 at 03:56 PM 0
Share

oh, in update, I'm stupid xD thanks

avatar image Bunny83 · Aug 02, 2014 at 04:18 PM 0
Share

@leoxs: If your question is answered, would you please mark your question as solved by accepting the answer?

tick an answer

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do I open a GUI on key press? 1 Answer

Cloud recognition in Vuforia 0 Answers

motion detection 0 Answers

Network Programming in Unity 2 Answers

Not able to send message from java to Unity using UnityPlayer.UnitySendMessage 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