Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 wbsnkpdk · Jun 23, 2011 at 03:57 AM · update

what's wrong with unity

My unity version is 3.1.0f4, and my CPU is Intel Core i5. I write these code in one java script's update():

print("in State_BeingShoot()"); transform.animation.Play("hit"); yield WaitForSeconds(1); mLife--; print("being shot mLife" + mLife);

There are two print statements, but in my log, I see that just one of them can be printed in one circle. By the way, there are someting wrong with the update() before: I write one print statement in update, it just print once. But when I write a variable and add 1 to it per cycle, it is printed normally. So what's the matter. Thank you for taking time reading this!

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
1

Answer by testure · Jun 23, 2011 at 04:11 AM

Update can't be used as a coroutine:

http://unity3d.com/support/documentation/ScriptReference/index.Coroutines_26_Yield.html

specifically:

Note that you can't use yield from within Update or FixedUpdate, but you can use StartCoroutine to start a function that can.

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 wbsnkpdk · Jun 23, 2011 at 06:13 AM 0
Share

Thank you! So, If I want the script to wait for a while, which function shoud I use? I want to use the function to wait the animation finishing playing.

avatar image testure · Jun 23, 2011 at 06:32 AM 0
Share

start the animation in a coroutine, and then start the coroutine from Update.

I don't use Javascript, so I can't give you code that you can use via copy/paste, but if you take a look at it, you should be able to interpret what i'm doing:

 IEnumerator DoAnimationThing()
 {
   animation.CrossFade("my animation");
   yield return new WaitForSeconds(2f);
 Debug.Log("this happens 2 seconds later.");
 }

 void Update()
 {
   if(startAnimation)
   {
     StartCoroutine(DoAnimationThing());
   }
 }

Javascript uses dynamic typing, so you obviously won't need the IEnumerator or void types.. in fact I don't think you have to use 'new' when returning WaitForSeconds either.. but yeah, look some of that stuff up on the unity docs and you'll get clear examples of how to do it in javascript.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Spawing a SpawnPoint with Raycast 0 Answers

How to implement Aggro into a AI script (Js) 0 Answers

NGUI panel wont hide 2 Answers

Main menu camera change script. 1 Answer

How draw a path using touch in c# 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