Animation script

My aim is it to press a key and the player takes out a gun. If you press the key again, he puts it back.
I’ve already got the animation, but I tried many scripts, but they didnn’t work.
Pls help me!

  1. Question: Should the transitions be bools, triggers floats or ints?
  2. Question: How can I write my C# script?
    If you press the key, the whole animation should be played and the gun should stay out. If you press the key again, another animation should be played.

You can use triggers or bools.

// this is a mere test, but it should get you started // put this within the update // not optimal though
if (Input.GetKeyDown("space"))
    GetComponent<Animator>().SetTrigger("DrawGun");