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 /
This question was closed Apr 14, 2013 at 07:28 AM by Fattie for the following reason:

Duplicate Question

avatar image
0
Question by zemog · Apr 14, 2013 at 06:59 AM · javascriptcoroutineyieldwaitforsecondswaypoint

Waypoint / Yield help

Hi guys

Basically Im trying to make a object go from waypoint[0] to waypoint[1] and when it reaches both its meant to pause for 5 seconds using yield. But instead it carries on in a loop. Ive tried everything I can think of, no idea what to do.

I based my code off of this guys http://answers.unity3d.com/questions/220547/waypointanimation-help.html if that helps.

 var waypoint : Transform[];
 var speed : float = 4;
 private var currentWaypoint : int;
 var test;
 
 
 function Start() 
 {            
     StartCoroutine("CoStart");
 }
 
 function CoStart() : IEnumerator
 {
     while (true)
         yield CoUpdate();
 }
 
 function CoUpdate () : IEnumerator
 {
     
     if(currentWaypoint < waypoint.length)
         {
             var WPtarget : Vector3 = waypoint[currentWaypoint].position;
             var moveDirection : Vector3 = WPtarget - transform.position;
             var velocity = rigidbody.velocity;
              
              
              
             if(moveDirection.magnitude < 1)
             {                                  
                 test = true; 
                 speed = 0;
                 if(test)
                 {
                     WaitFiveSeconds();
                     currentWaypoint++;
                     
                 }      
             }             
             else
             {
                    if(!test)
                    {
                        speed = 4; 
                       
                    }
             }
             if (currentWaypoint > 1)
             {                
                    currentWaypoint = 0;
             } 
         velocity = moveDirection.normalized*speed; 
         rigidbody.velocity = velocity;        
         }
 }
         
 function WaitFiveSeconds() 
 {
     
     WaitForSeconds(5);         
     test = false;    
 }

Like I said, Ive tried everything I can think off, maybe you guys can help :)

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

  • Sort: 
avatar image
0
Best Answer

Answer by Fattie · Apr 14, 2013 at 07:28 AM

if I'm not mistaken you are using "waitForSeconds" totally incorrectly. it's more like

 yield WaitForSeconds(5)

urge you to just use Invoke() for simple timers for beginners in Unity, rarely necessary to use yield.

urge you to SEARCH on here for literally 1000s of questions on using yield correctly. your code is not right at all. you will find literally 1000s of questions on using yield correctly

also unityGEMS.com

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

Follow this Question

Answers Answers and Comments

12 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

Related Questions

yield works, but yield WaitForSeconds does not? 1 Answer

Load Level when dead for 1 second 2 Answers

Playing footsteps with interval 1 Answer

Yield WaitForSeconds doesn't work 1 Answer

Need to call yield TWICE ??? (ANSWERED) 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