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
1
Question by BlisterFingers · Jan 24, 2016 at 04:08 PM · animationscaling

Make object scale pulse smoothly when selected.

I have a cube in my scene and I wish to pulse it's scale when the user points at it to indicate that it is the selected object.

Currently I'm using Mathf.PingPong() which works but it causes the object to suddenly snap to the current ping-pong value when it's first selected. I also would like the object to transition it's scale back to 1 when it's unselected.

Here's what I have so far. SetSelected is called with the appropriate value from another script.

 using UnityEngine;
 
 public class NodeObject : MonoBehaviour {
 
     private const float MIN_SCALE = 0.75f;
 
     private bool selected = false;
 
     private GameObject childMesh;
     private GameObject childCollider;
 
     // Use this for initialization
     void Start () {
         childMesh = transform.FindChild("Mesh").gameObject;
         childCollider = transform.FindChild("Collider").gameObject;
     }
     
     // Update is called once per frame
     void Update () {
         if (selected) {
             float scale = MIN_SCALE + Mathf.PingPong(Time.time * 0.2f, 1f - MIN_SCALE);
             childMesh.transform.localScale = new Vector3(scale, scale, scale);
         }
     }
 
     public bool IsSelected() {
         return selected;
     }
 
     public void SetSelected(bool value) {
         selected = value;
     }
 }
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
4
Best Answer

Answer by Fattie · Jan 24, 2016 at 04:08 PM

Many developers just use iTween for this sort of thing - it's free.

I've actually never used it, and only tried it recently and it's a great time saver.

I used their PunchScale PunchScale call and it works fine.

I used it to bounce a UI button, when clicked. I just put this script on anything I want to bounce, and call DoPulse

 public class SoundButtonPulse:MonoBehaviour
     {
     public void DoPulse()
         {
         System.Collections.Hashtable hash =
                   new System.Collections.Hashtable();
         hash.Add("amount", new Vector3(0.15f, 0.15f, 0f));
         hash.Add("time", 1f);
         iTween.PunchScale(gameObject, hash);
         }
     }

Normally I obsessively hand-write bounces and twists, but really it's all you need 99% of the time .. good one, iTween dudes

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 BlisterFingers · Jan 24, 2016 at 09:51 PM 2
Share

Thanks. Took me 5 $$anonymous$$utes to get the result I wanted with iTween. Add this as an answer and I'll accept it.

avatar image Fattie BlisterFingers · Jan 24, 2016 at 10:03 PM 1
Share

Thank goodness it worked, cheers. I love 5 $$anonymous$$. solutions :O

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Changing the size of an animated 2D object 0 Answers

2D Animations Scaling Away From The Floor 0 Answers

blender rigged animation plays, but scaling of the model does not. 0 Answers

DOTween & how to undo SetBlendableScaleBy tweens that get killed 0 Answers

Why does my animation warp when I adjust the scale in Unity? 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