Multiple animations on 1 object

Hello,

i just need to say, before i start, that i am a bit of a noobie to unity scripting.

basically i would like to know how (if it’s possible) to put 2 animations on to 1 object. i am making a gun and i have the left mouse click assigned to fire, so thats good. this is the code i used for that;

function Update () {

if ( Input.GetButtonDown(“Fire1”) ) {

   transform.animation.Play("Default Take 1");

}

}

so now i have made a new animation on the same gun, to reload. but i cant get it to work. i want to be able to push the ‘R’ key for the reload animation to play.
this is the code for that;

function Update () {

if ( Input.GetKeyDown(KeyCode.R) ) {

transform.animation.Play(“Reload”); }

}

when i play the game and click with the left mouse key, it fires the gun like it should, but when i press the ‘R’ button it come up with an error saying:

The animation state Reload could not be played because it couldn’t be found!

Does anyone have an idea of how to get both the inputs to start the animations which i have set them to?

You go to “window>animation” on the object. Then inbetween the name of the current animation and sample is two arrows, one pointing up and one pointing down. Click that and the click “[Create new clip]”

Did you set the “Animations” size to 2 in the inspector? If not click the object that plays the animations and you will see “Animations” followed by an arrow. If you click the arrow it will open up a few things you can change, you have two animations(Fire & Reload). set the size to 2, and then drag the Fire and Reload animations on to the “Element 0 and Element 1” Please respond if you have any questions. I tested it out for myself and iv’e got it working.

[game object’s name].GetComponent().Play(“animation’s name”);

Animation Component’s size = number of animations