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
1
Question by m0nky · Aug 14, 2012 at 12:06 PM · itweenscaling

iTween Scale up then down again

Heyho,

im currently trying to implement a scaler for buttons, on MouseEnter it should scale up and on MouseExit it should return to the original value.

 onMouseEnter: iTween.ScaleBy(gameObject, iTween.Hash("x", 1.05, "z", 1.05, "default", .1));
 onMouseExit: iTween.ScaleBy(gameObject, iTween.Hash("x", 0.95, "z", 0.95, "default", .1));

The problem with my current code is, that it will become smaller and smaller over lots of OnMouseEnter / OnMouseExit's.

Example: Stating value: 1200 after scaling it up: 1260 after scaling down again: 1197

Got any ideas? Regards

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
1

Answer by Paulo-Henrique025 · Aug 14, 2012 at 12:16 PM

I think your solution is to use iTween.ScaleTo(). When you ScaleBy() the expected behavior is exactly what you are describing, the button will scale up +5 OnMouseEnter and them -5 OnMouseExit, if there is a transformation occurring during a new mouse event the ScaleBy will Add ou Subtract the value from the current scale which is in middle of a transformation.

When you use ScaleTo no matter the current scale it will scale to the desired size.

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
1

Answer by Lex · May 30, 2016 at 01:44 AM

I know it's a veeeeeery old question but I couldn't resist to comment on this.

The problem here is simple math, just follow me:

If you scale 100 up 5% you'll get this: 100 * 1.05 = 105

If you scale the result down 5% you'll get this: 105 * 0.95 = 99.75

Can you see? When you're working with percentages you can't just add and subtract the same % and expect it to come back to where it was.

So what you actually need is to scale down so it goes back to the original value. What you'll need is the following:

  onMouseEnter: iTween.ScaleBy(gameObject, iTween.Hash("x", 1.05, "z", 1.05, "default", .1));
  onMouseExit: iTween.ScaleBy(gameObject, iTween.Hash("x", 95.2380f, "z", 95.2380f, "default", .1));

And you might still get accumulative error, but I guess this time it won't be visible.

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 carloalbores123 · Mar 10, 2019 at 04:56 AM

I'm sorry to revive this thread but for the sake of others who also encounter this (like me) up to this date, the probably easiest method is as @Paulo-Henrique025 answered. Just use iTween.ScaleTo instead of ScaleBy. This solved mine as it scales up / down nearly the desired Vector 3 values.

Make sure to have it like this:

Vector3 desiredSize = new Vector3 (desired_x,desired_y,desired_z);
float t = 1f;

iTween.ScaleTo(gameobject, desiredSize, t);

just replace the values you needed..

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

10 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

Related Questions

Parallel animation play using iTween 1 Answer

How to keep GUI's shape while scaling on both X & Y axis with max/min values,How to keep GUI's initial shape while scaling 0 Answers

How to re-scale UI Mask in realtime 0 Answers

RectTool scale in both direction,RectTool scale in both directions 0 Answers

Accidentally did 'something' and now positioning is all out of whack (canvas, camera, scaling?) 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