- Home /
How to play an animtion when you press a key
i have looked through many tutorials and have tried many things but nothing is working. what i want to do is link my shooting animation with when i left click and when i press W it will play my gun movement animation (kind of like a walk animation) but nothing works i will make the script attach it and nothing happens this is the two scripts i have tried.
function Update()
{
if(Input.GetKeyDown("w"))
{
// Plays the reload animation - stops all other animations
animation.Play("walkAnimation", PlayMode.StopAll);
}
}
and
if( Input.GetKey("w") )
animation.CrossFade ("walkAnimation");
any help would be appreciated thanks you :)
Answer by Hyperion · Jan 07, 2013 at 05:52 AM
Use Mecanim. New feature of Unity. The old animation legacy system is highly not recommended. For a good tutorial, search in YouTube Mecanim tutorial and choose the 49 minute one. So you're using a rigged humanoid model? In the prefab settings, change the import scale do 1, you've probably done that. Now, go to Rig tab, choose humanoid from the drop down menu, and configure. Then add a Animator Controller.
Answer by jdcluck56 · Jan 07, 2013 at 08:15 AM
thank you for your help ill check out the new features thanks again