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 TinyUtopia · Feb 18, 2011 at 04:22 PM · raycasttransformscale

rollover scale script problem

I would like to have an object scale when the mouse is positioned over it. I can get it to scale, but I can't get the object to return to it's original size OnMouseExit. What am I doing wrong?

function OnMouseEnter () { renderer.material.color = Color.red; transform.localScale += transform.localScale*0.1; }

// Assigns a white color to the material // attached to this mesh.

function OnMouseExit () { renderer.material.color = Color.white; transform.localScale -= transform.localScale*0.1; }

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 Jesse Anders · Feb 18, 2011 at 05:09 PM 1
Share

The math you're using won't actually return the scale to its original value. However, the difference will be $$anonymous$$imal in this particular case, so I doubt that's the problem. As for what the problem might be, does the color get reset to white when you expect it to? Or is that not happening either?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Travis 18 · Mar 28, 2011 at 04:05 PM

You're object won't return to it's original size because you're performing an operation on the local scale after you've changed it. So if you local scale starts at 100, and you add ten percent you end up with 110. If you then subtract ten percent of THAT, you get 110 - 11 = 99.

It might be a negligible amount, but you can avoid it by saving the original value in the OnMouseEnter function and calling it later, like so:

var oldScale;

function OnMouseEnter(){ oldScale = transform.localScale; transform.localScale += transform.localScale.0.1; }

function OnMouseExit() { transform.localScale = oldScale; }

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

No one has followed this question yet.

Related Questions

Scale of GameObject is reset when enable an attached Animator component 1 Answer

How to covert a rectTransform scale to world scale? 1 Answer

Enemy gameObject didn't move 1 Answer

Raycast won't work after Camera transforms position. Please help! 1 Answer

OnSceneGUI has odd behaviour with multiple objects selected 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