Unity: Apply an different animation with Animator

#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.

<img width="1552" alt="Screen Shot 2016-02-05 at 13.49.04.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/b7c3d70f-4ded-7d94-687f-365732957a7e.png">

Each object needs to have an Animator component.

<img width="527" alt="Screen Shot 2016-02-05 at 13.49.26.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/44a120ad-bc16-08f1-81d8-e99589556c23.png">

## 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.

<img width="1552" alt="Screen Shot 2016-02-05 at 13.50.01.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/24e371c2-23e5-8d9b-556e-c2699beb35b3.png">


<img width="1552" alt="Screen Shot 2016-02-05 at 13.50.16.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/87882814-24ae-3797-eaed-b9d3b540f70c.png">


<img width="1552" alt="Screen Shot 2016-02-05 at 13.50.25.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/76095b26-9467-484c-e3c1-f2a9c5735b5b.png">


<img width="876" alt="Screen Shot 2016-02-05 at 13.58.30.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/db5ff804-2fbf-6dee-fd72-0fed203a36c7.png">



<img width="1552" alt="Screen Shot 2016-02-05 at 13.50.36.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/67dfb725-3a66-60f1-911c-510c01f2aa41.png">


<img width="363" alt="Screen Shot 2016-02-05 at 13.51.03.png" src="https://qiita-image-store.s3.amazonaws.com/0/53282/a4ca5a56-e00c-04d2-a5ca-a966685d7163.png">


```csharp
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) {
	//
	//}
}
```