Gun Firing Animation

I am having troubles setting up my gun animation. I created a gun and am trying to set up a simple shoot animation which is called in the script when the Fire1 button is pressed.

void Update() {
    If (Input.GetButtonDown ("Fire1") ) {
        animation.Play("Shooting", PlayMode.StopAll);
    }
}

I keep getting the error

“MissingComponentException: There is no ‘Animation’ attached to the “Gun” game object, but a script is trying to access it.”

I have a Animator Component attached to the Gun so I’m not sure why I’m getting this error. Could someone help?

On a side note, when I initiate the game the animation starts once, I am also unable to disable this initial animation. If I could get some advise for how to stop this it would be much appreciated

I am relatively new to Unity and am using C# scripts, so any help would be greatly appreciated.

You say you have an Animator component and you are using Animation component, those are not the same.

In Animator, you don’t really use scripting, you place animations that are linked with transitions. Those transitions contains the conditions.
For instance, you have an idle animation by default which is the one that runs when no other conditions are met. Then you have the Shooting animation. You link those two back with a transition that use a boolean shooting.

In the script you do :

if (Input.GetButtonDown ("Fire1") )
    GetComponent<Animator>().SetBool("shooting", true);

when you shoot and that is it. When animation is over, it gets back to default animation.
Also, your if has a typo on the front, it should small i.