Animator
When you have a bunch of animations (or a few of them), using the Unity's Animator works well. This tiny tip give you how to apply a different animation based on the scale of the attached gameobject.
Each object needs to have an Animator component.
Screenshots
The following images might help to grasp how each inspector works.
Animators need to have at least one parameter to decide what kind of transition is going to be triggered.
using UnityEngine;
using System.Collections;
public class CubeAnimBehaviour : StateMachineBehaviour {
private float xScale;
// OnStateEnter is called before OnStateEnter is called on any state inside this state machine
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
// first, need to check the target scale. based on this, create transition
xScale = animator.transform.localScale.x;
// then, set the next animation
if (xScale == 1.0) {
animator.SetInteger ("Animation Mode", 0);
} else if (xScale == 2.0) {
animator.SetInteger ("Animation Mode", 1);
} else if (xScale == 3.0) {
animator.SetInteger ("Animation Mode", 2);
}
}
// OnStateUpdate is called before OnStateUpdate is called on any state inside this state machine
//override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateExit is called before OnStateExit is called on any state inside this state machine
//override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateMove is called before OnStateMove is called on any state inside this state machine
//override public void OnStateMove(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateIK is called before OnStateIK is called on any state inside this state machine
//override public void OnStateIK(Animator animator, AnimatorStateInfo stateInfo, int layerIndex) {
//
//}
// OnStateMachineEnter is called when entering a statemachine via its Entry Node
//override public void OnStateMachineEnter(Animator animator, int stateMachinePathHash){
//
//}
// OnStateMachineExit is called when exiting a statemachine via its Exit Node
//override public void OnStateMachineExit(Animator animator, int stateMachinePathHash) {
//
//}
}