- Home /
Changing the size of an animated 2D object
Hi everyone!
I have a problem with resizing my animated 2D gameobject during runtime. Some of my animations are stored in different sizes, so I'd like to fix this in Unity. I have tried two different methods, but none of them are working properly for me.
The first one:
-at the Animation tab I'm selecting the animation
-then I hit the Record button, and set the Transform's Scale from 0.6 to 0.3 for example
-then I hit Record again to finish it
What happens: the resizing effect doesn't happen immediately, it's continuous.
Check video: link text
The second one:
-I'm trying to set the scale from a script
-Here's my code:
     private Transform tra;
     private Animator anim;
 
     void Start ()
     {
         tra = GetComponent<Transform> ();
         anim = GetComponent<Animator> ();
     }
     
     void Update ()
     {
         if (Input.GetKeyDown (KeyCode.W)) {
             anim.SetTrigger ("Attack");
         }
 
 
         if (AnimatorIsPlaying("wildpig_attack")) {
             tra.localScale = new Vector3 (0.3f, 0.3f, 1f);
         }
         else {
             tra.localScale = new Vector3 (0.6f, 0.6f, 1f);
         }
 
     }
 
     bool AnimatorIsPlaying(string stateName)
     {
         if (anim.GetCurrentAnimatorStateInfo (0).IsName (stateName)) {
             return true;
         } else {
             return false;
         }
     }
What happens: the resize effect only happens after the half of the animation is already played.
Check video: link text
If anyone has an idea how to solve this, it would be a great help. Thanks in advance!
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                