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 Agent-6141 · Mar 16, 2013 at 07:00 AM · updatefunctiongridtron

How do i delay function Update

Hi i'm working on a tron game for class and i'm running into a problem. I have a count down that plays then the vehicle moves and all that works fine but while the vehicle is sitting the player is still able to turn the vehicle left and right while its sitting there. To yield it from moveing i had var speed:int = 0 then i did speed = 0 then yield WaitForSeconds (5); then speed = 130 but that just makes it stop. i dont want to be able to turn either here is my turning script... i was wondering how to delay that script as well. I thought maybe if i could delay the function update for five seconds that would work but i dont know if thats possible.

#pragma strict function Update () { //makeing the bike rotate 90 degrees at a time if(Input.GetButtonDown("RIGHT")) { transform.Rotate(Vector3(0, 90, 0)); } if(Input.GetButtonDown("LEFT")) { transform.Rotate(Vector3(0, -90, 0)); } }

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

Answer by robertbu · Mar 16, 2013 at 07:34 AM

You could put a boolean value in the file, and check it:

At the top of the file:

 var raceStarted = false;  // Set this to true when the race starts

Then change the two lines in Update().

 if(raceStarted && Input.GetButtonDown("RIGHT")) { transform.Rotate(Vector3(0, 90, 0)); } 
 if(raceStartee && Input.GetButtonDown("LEFT")) { transform.Rotate(Vector3(0, -90, 0)); } }
Comment
Add comment · Show 4 · 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 Agent-6141 · Mar 17, 2013 at 01:13 AM 0
Share

its not working =( heres what i have now var raceStarted:boolean = false; function Start (){ pause (); } function Update () { //makeing the bike rotate 90 degrees at a time if(raceStarted && Input.GetButtonDown("RIGHT")) { transform.Rotate(Vector3(0, 90, 0)); } if(raceStarted && Input.GetButtonDown("LEFT")) { transform.Rotate(Vector3(0, -90, 0)); } } function pause () { raceStarted = false; yield WaitForSeconds (5); raceStarted = true; }

avatar image robertbu · Mar 17, 2013 at 02:39 AM 0
Share

"its not working" doesn't give me a lot to go on. I don't have your project, so I cannot see what is happening. Can you describe what it is doing? Can you still turn the vehicle or are never able to turn the vehicle?

avatar image Agent-6141 · Mar 17, 2013 at 03:37 AM 0
Share

wait yes it works never $$anonymous$$d i made a mistake thank you very much for your support and being patient with me.

avatar image fafase · Mar 17, 2013 at 11:42 AM 0
Share

Same but different, I usually write it this way

 void Update(){
    if(!raceStarted)return;
    //rest of code
 }

It does the same, I just like it more since it makes me think it looks more clear.

Just a question of taste though.

(well actually you only check it once and that is it, so slightly saving cycles)

avatar image
0

Answer by marcelobr · Mar 17, 2013 at 01:31 AM

Quaternion.Slerp

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 Azial · Mar 17, 2013 at 11:53 AM

Try this:

 yield waitThenStart(3.0); //"waitThenStart" function gets called
 
 function Awake() {
     enabled = false;
 }
 
 function waitThenStart(startIn : float) {
     yield WaitForSeconds(startIn); //wait until the seconds passed we hand over in the parameter
     enabled = true; //activate the "Update function"
 }
 
 function Update() {
     ... //normal code we want to exucuted every frame
 }
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 fafase · Mar 17, 2013 at 12:20 PM 0
Share

What is that supposed to do?

this

 yield waitThenStart(3.0);

is outside any function, this won't even compile.

avatar image Azial · Apr 06, 2013 at 09:45 AM 0
Share

Oh yes, it will :) You can even keep off the "yield" before I figured out recently.

So the script does this: 1. disables the Update function right away when the objects awake. 2. waitThenStart gets called 3. wait 3.0 seconds then enables the Update function

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

13 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

Related Questions

Im a bit confused on a simple script 1 Answer

Drawing to the scene from an EditorWindow 5 Answers

Aiming with function "Update" not working 0 Answers

Update() doesnt call method or modify values 1 Answer

Update not being called 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