How can I disable animation?

Hi there! I’ve got a problem when the player has to make a multiple choice by pressing this or that button. His decision determines which animation will be on.
The problem is - I can’t disable the animation that is not chosen by the player.
So far I did this:

using UnityEngine;
using System.Collections;


public class PressToMove: MonoBehaviour 

{
	public Animation A1toA2;
	public Animation A1toA3;
	
	void Update ()

	{	

A1toA2 = gameObject.GetComponent<Animation>();	
A1toA3 = gameObject.GetComponent<Animation>();
		
		if(Input.GetKeyDown("1"))
    animation.Play("A1toA2");
	A1toA3.enabled = false;
		
       if(Input.GetKeyDown("2"))
    animation.Play("A1toA3");
	A1toA2.enabled = false;

}
}

But nothing happens when I press either 1 or 2.

I advise you to use the Animator, which is a finite state machine, allowing you to make the decision graph and picking which animation to choose based on a parameter (boolean, int, trigger,…).

Check it out and enjoy the flexibility:

http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/animate-anything

You need braces after if condition ,

 if(Input.GetKeyDown("1"))
{
     animation.Play("A1toA2");
     A1toA3.enabled = false;
}

 
        if(Input.GetKeyDown("2"))
{
     animation.Play("A1toA3");
     A1toA2.enabled = false;
}

‘A1toA2’ and ‘A1toA3’’ both point to the same ‘Animation’ component… that is disabled so no anim is replayed.

I’ve never tried to use an animation before but don’t you have to use it like this?

animation.Play(A1toA2);

instead of

animation.Play("A1toA2");