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 Solitude01 · Nov 08, 2011 at 09:05 AM · javascriptitween

iTween ValueTo onUpdateParams passing

I'm trying to make 4 HP bar to drop down smoothly using iTween The HP bar is a 64-pixel-wide GUITexture

 var hpBar : GUITexture[];
 
 function Tween()
 {
     iTween.ValueTo (gameObject, iTween.Hash("from"        , hpBar[0].pixelInset.width,
                                                         "to"        , chara0curHP/chara0totalHP*64,
                                                         "time"        , 0.5,
                                                         "onUpdate"    , "HPBar0Tween")
                         );
     iTween.ValueTo (gameObject, iTween.Hash("from"        , hpBar[1].pixelInset.width,
                                                         "to"        , chara1curHP/chara1totalHP*64,
                                                         "time"        , 0.5,
                                                         "onUpdate"    , "HPBar0Tween")
                         );
     iTween.ValueTo (gameObject, iTween.Hash("from"        , hpBar[2].pixelInset.width,
                                                         "to"        , chara2curHP/chara2totalHP*64,
                                                         "time"        , 0.5,
                                                         "onUpdate"    , "HPBar0Tween")
                         );
     iTween.ValueTo (gameObject, iTween.Hash("from"        , hpBar[3].pixelInset.width,
                                                         "to"        , chara3curHP/chara3totalHP*64,
                                                         "time"        , 0.5,
                                                         "onUpdate"    , "HPBar0Tween")
                         );
 }
 
 function HPBar0Tween(val : int) { hpBar[0].pixelInset.width = val;}
 function HPBar1Tween(val : int) { hpBar[1].pixelInset.width = val;}
 function HPBar2Tween(val : int) { hpBar[2].pixelInset.width = val;}
 function HPBar3Tween(val : int) { hpBar[3].pixelInset.width = val;}

My question is, how can I cut down the number of onUpdate functions by providing the 2nd parameter to onUpdateParams function? I've tried to supply Hashtable as argument for onUpdateFunction and iTween doesn't accept it. I've already tried to supply JavaScript Object as the argument and iTween treat them as int

What would be my other options rather than this long,messy, unelegant way of handling it?

I appreciate any feedback

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 fanling3 · May 05, 2012 at 03:46 AM 0
Share

I have the same question

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Wolfram · Jul 05, 2012 at 01:06 PM

With the solution prevented by karsten here, you only need to change 3 lines of code in iTween, and can then use an inline delegate for "onupdate"/"oncomplete"/"onstart" (instead of an explicit function) to execute arbitrary code with any parameters you like.

So for example you could then do something like:

         string colorToChange="_Color";
         iTween.ValueTo(gameObject, iTween.Hash(
             "from", a,
             "to", b,
             "onupdate", (Action<object>) (newVal => {
                 Debug.Log("running iTween onupdate for "+colorToChange+" "+(float)newVal);
                 renderer.material.SetColor(colorToChange,Color.white*(float)newVal);
             }
         ));
 

NOTE: I don't know whether this works in US/JS, too, or whether the syntax would change.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Using iTween ValueTo with onupdateparams 1 Answer

using iTween.ValueTo for the rotation of a GameObject with RotateAround 1 Answer

iTween with multiple ValueTo calls on same GameObject 1 Answer

Using private class strings with iTween event calls 0 Answers

iTween JavaScript orienttopath bug? 0 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