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
0
Question by Chrissyprice · Jan 12, 2015 at 10:23 AM · inputkeygetdown

troubles with changing scenes

hellooo, i'm having a little problem with switching scenes on my game, what im doing is trying to make a playable tutorial, there are some visuals on the screen telling you to press 'a' and i want it so that when you press 'a' , the game waits 3 seconds before loading the next scene, here is the code i've made and there are no errors but the game simply does not move to the next screen.

 #pragma strict
 
 function Start () {
 if (Input.GetKeyDown("a"))//pressing the a key loads the game level, 
 {
     yield WaitForSeconds (3);
     Application.LoadLevel ("tutorial2");
 }
 }
 
 function Update () {
 
 
 
 }
 
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 UziMonkey · Jan 12, 2015 at 10:31 AM 0
Share

Note that you've put your code in the Start method. This method is called once when the script component is enabled. You probably want this code to go in Update ins$$anonymous$$d.

3 Replies

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

Answer by brockk · Jan 12, 2015 at 10:34 AM

Hi Chrissyprice ,

use this code to solve problem

function Update () {

if (Input.GetKeyDown("a")) {
changescene ();
}

}

function changescene () { yield WaitForSeconds(3); Application.LoadLevel ("tutorial2"); }

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 Chrissyprice · Jan 12, 2015 at 12:12 PM 0
Share

this code worked perfect cheers man, could i ask also how i would apply this if i had to press 'a' and left shift at once?

what i guessed isnt right if (Input.Get$$anonymous$$eyDown("a")) && (Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift){ changescene (); }

avatar image brockk · Jan 12, 2015 at 12:33 PM 0
Share

Hi Chrissyprice ,

function Update () {

if (Input.Get$$anonymous$$eyDown("a")&&Input.Get$$anonymous$$ey($$anonymous$$eyCode.LeftShift))//pressing the a key loads the game level, {
changescene ();
}

} function changescene () { yield WaitForSeconds(3); Application.LoadLevel (1); }

pls accept answer

happy to help you

avatar image
0

Answer by Josh Naylor · Jan 12, 2015 at 10:26 AM

Check out the documentation for a function called Invoke

 Invoke( "Load", 5 );
  
  function Load(){
      Application.LoadLevel(...);
  }

This calls the method "Load" after 5 seconds.

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 Bunny83 · Jan 12, 2015 at 10:36 AM

Start is executed only once, so your if statement is only checked once at start. You have to do that check in Update and your delayed level loading in a seperate coroutine:

 static var waitForLevelLoad = false;
 function Update ()
 {
     if (Input.GetKeyDown("a"))
     {
         LoadLevelDelayed("tutorial2", 3);
     }
 }
 
 function LoadLevelDelayed(levelName, delay)
 {
     if (waitForLevelLoad)
         yield break;
     waitForLevelLoad = true;
     yield WaitForSeconds (delay);
     waitForLevelLoad = false;
     Application.LoadLevel(levelName);
 }


The boolean "waitForLevelLoad" prevents the user from "queueing" multiple loadlevels at the same time.

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

6 People are following this question.

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

Related Questions

Noob - Use the ESC, Shift and Command Key?? 1 Answer

GUI Label & KeyCode Doesn't Work 1 Answer

Is there a way to get precise input ? 1 Answer

No keyboard events detected after any key is held. 0 Answers

Input Key named: LeftAlt is unknown 2 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