anim + audio change with key press?

Hey a supernoob question! Am an animator just getting going with scripting. I’ve searched the forums for ages trying to find an explaination that i could understand but no luck so far.

My problem is that while I’m able to assign keys to trigger character animations I haven’t been able to figure out how to assign different audioclips to the animations. so that when a player presses “2” for instance it plays an animation and an audioclip at the same time. and then if i press “3” it will play another anim and audio clip. It seems like it should be easy so i hope that someone can help. It’d be great if you can–Thanks!!!

heres cut down version of the character anim that works so far. I just have no idea how to add audioclips into this equation.

var idle : UnityEngine.Animation;
var anim : UnityEngine.Animation;

animation.wrapMode = WrapMode.Loop;
animation["idle"].wrapMode = WrapMode.Loop;
animation["Anim01"].wrapMode = WrapMode.Once;

function Update () {                 
	    
    if (Input.GetKey ("2"))
    {
    	animation.CrossFade("idle");
    }
    if (Input.GetKey ("3"))
    {
    	animation.CrossFade("anim");
    }
}

:sweat_smile:

Any advice on this topic would be much appreciated as I have an up coming deadline. If you help me with this I will love you forever as Triggering animations and sound is all that I need Unity for.

is this in the right ball park?

    if (Input.GetKey ("2"))
    {
    	animation.CrossFade("idle");
    }
    if (Input.GetKey ("2")) {
		audio.Play("idleaudio");
		
    }

Welcome to the forum, Toots!

The AudioSource class has a method called PlayOneShot which lets you set an AudioClip to play immediately.