Play a second animation

Hello!
I have a game object with an animation component attached. On the animation component, I have 2 animation clips. I need to play both of them through script and I’m not sure how.
I need it to when I press “P”, the first animation clip goes, then when I press “O”, the second one plays.
Thanks.

Try this

  if (Input.GetKeyDown(KeyCode.P))
        {
            gameObject.GetComponent<Animation>().Play("animation1_name");
        }
  if (Input.GetKeyDown(KeyCode.O))
        {
            gameObject.GetComponent<Animation>().Play("animation2_name");
        }

I am getting an error:
"Please attach an animation clip with the name “Rules_Panel_Anim_Up” or call this funcation only for existing animations.
The thing is though is that I do have 2 animation clips attached to the animation component, one being the rules_panel_anim_up.
I’ve doubled check spelling and it still isn’t working.

Edit: Got it working! Ends up the second animation needed to be marked “Legacy”.
I am somewhat new to coding and the inspector, so I’m not quite sure what legacy means, either way I got it working though. Thanks for the bit of code!