key press script

hi all ,
I have a question about scripting
I ll try explain ,
I have an animation called “playeranimation”
I want to play this when i press “m” or some other key ,
do you have any code for this?

I really recommend you download a tutorial to work with. The 3D platformer is a nice one, look around though find one that fits close to your main goal.

if(Input.GetButtonDown ("m")
{	
animation.CrossFadeQueued("playeranimation",1,QueueMode.PlayNow);
}

You’ll need to define your input.

thank you very much , I ll try :slight_smile:

I tried tried tried :frowning:

but I cant .

i define a new input key in input manager , than draw you code you posted but there is no play :frowning:
I think there must be any var: before this code
function Update (){
{ if(Input.GetButtonDown (“m”)

animation.CrossFadeQueued(“my”,1,QueueMode.PlayNow);
}
}

help me people :frowning:

try animation.crossfade(“my”,0.2);

If that doesn’t work it would be a good idea to 1) Look up “Unity animation.crossfade” See if you can find related functions from there. 2) Check the code of an example script in any given example project (except maybe Third Person Shooter since that’s pretty advanced) since they are all filled with different ways to call animations.
Hope it helps, if you really get lost, try a unity question instead of forums. Maybe you’ll get more help than just me from there.