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 NinjaRubberBand · Jun 17, 2014 at 02:49 PM · yieldwaitforsecondsif

How do i use yield WaitForSeconds(); in this script?

The script is pretty long:

 #pragma strict
 
 var steps : Transform[];
 var stepsNum : int;
 
 
 
 
 function Start () {
 
 }
 
 function Update () {
 stepsNum = gameObject.Find("DiceMug").GetComponent(Dice).player1steps;
 
 if(stepsNum == 1) {
 transform.position = steps[1].position;     
 }
 
 if(stepsNum == 2) {
 transform.position = steps[2].position;     
 }
 
 if(stepsNum == 3) {
 transform.position = steps[3].position;     
 }
 
 if(stepsNum == 4) {
 transform.position = steps[4].position;     
 }
 
 if(stepsNum == 5) {
 transform.position = steps[5].position;     
 }
 
 if(stepsNum == 6) {
 transform.position = steps[6].position;     
 }
 
 if(stepsNum == 7) {
 transform.position = steps[7].position;     
 }
 
 if(stepsNum == 8) {
 transform.position = steps[8].position;     
 }
 
 if(stepsNum == 9) {
 transform.position = steps[9].position;     
 }
 
 if(stepsNum == 10) {
 transform.position = steps[10].position;     
 }
 
 if(stepsNum == 11) {
 transform.position = steps[11].position;     
 }
 
 if(stepsNum == 12) {
 transform.position = steps[12].position;     
 }
 
 if(stepsNum == 13) {
 transform.position = steps[13].position;     
 }
 
 if(stepsNum == 14) {
 transform.position = steps[14].position;     
 }
 
 if(stepsNum == 15) {
 transform.position = steps[15].position;     
 }
 
 if(stepsNum == 16) {
 transform.position = steps[16].position;     
 }
 
 if(stepsNum == 17) {
 transform.position = steps[17].position;     
 }
 
 if(stepsNum == 18) {
 transform.position = steps[18].position;     
 }
 
 if(stepsNum == 19) {
 transform.position = steps[19].position;     
 }
 
 if(stepsNum == 20) {
 transform.position = steps[20].position;     
 }
 
 if(stepsNum == 21) {
 transform.position = steps[21].position;     
 }
 
 if(stepsNum == 22) {
 transform.position = steps[22].position;     
 }
 
 if(stepsNum == 23) {
 transform.position = steps[23].position;     
 }
 
 if(stepsNum == 24) {
 transform.position = steps[24].position;     
 }
 
 if(stepsNum == 25) {
 transform.position = steps[25].position;     
 }
 
 if(stepsNum == 26) {
 transform.position = steps[26].position;     
 }
 
 if(stepsNum == 27) {
 transform.position = steps[27].position;     
 }
 
 if(stepsNum == 28) {
 transform.position = steps[28].position;     
 }
 
 if(stepsNum == 29) {
 transform.position = steps[29].position;     
 }
 
 if(stepsNum == 30) {
 transform.position = steps[30].position;     
 }
 
 if(stepsNum == 31) {
 transform.position = steps[31].position;     
 }
 
 if(stepsNum == 32) {
 transform.position = steps[32].position;     
 }
 
 if(stepsNum == 33) {
 transform.position = steps[33].position;     
 }
 
 if(stepsNum == 34) {
 transform.position = steps[34].position;     
 }
 
 if(stepsNum == 35) {
 transform.position = steps[35].position;     
 }
 
 if(stepsNum == 36) {
 transform.position = steps[36].position;     
 }
 
 if(stepsNum == 37) {
 transform.position = steps[37].position;     
 }
 
 if(stepsNum == 38) {
 transform.position = steps[38].position;     
 }
 
 if(stepsNum == 39) {
 transform.position = steps[39].position;     
 }
 
 if(stepsNum == 40) {
 transform.position = steps[40].position;     
 }
 
 if(stepsNum == 41) {
 transform.position = steps[41].position;     
 }
 
 if(stepsNum == 42) {
 transform.position = steps[42].position;     
 }
 

What i want is for every: if(stepsNum == number) { transform.position = steps[number].position;
}

it is like this: if(stepsNum == number) { yield WaitForSeconds(somenumber); transform.position = steps[number].position;
}

 But as you probably know, you cant use waitforseconds in function Update. 
 How can i make this happen in a other way?
 
 
 
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by OrbitGames · Jun 17, 2014 at 03:07 PM

To shorten your code you could either put it all in a for loop

for (int i = 1; i < 42; i ++) { if (stepsNum == i) { transform.position = steps[i].position; } }

or just use

transform.position = steps[stepsNum].position;

sorry for the unwanted bit.

I would make a counter which you subtract Time.deltaTime from every Update.

If the timer is smaller than zero (!important: Timer < 0 not Timer == 0) execute your position change.

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 NinjaRubberBand · Jun 18, 2014 at 05:30 PM 0
Share

Im not very good at loops, can you explain a little better?

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

22 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 avatar image

Related Questions

Help with a simple conversation script? 0 Answers

no "pointers" to get directly to a variable passed to a function? 1 Answer

Getting an error when trying to yield 2 Answers

is there any function call will be call after i activate an object ? 1 Answer

Yield Not Working - While Loop 3 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