Hello I’m fairly new to Unity when it comes to scripting. I spent some time animating a model in blender. I successfully imported the model and its animations into Unity as they play in the preview and I’ve set their start and stop times appropriately. However the script I’ve created doesn’t seem to work as upon pressing a certain key the animation does not play. Here is my script:
function Update()
{
if(Input.GetKeyDown("d"))
{
animation.Play("Walk");
}
else if(Input.GetKeyDown("a"))
{
animation.Play("Walk");
}
else if(Input.GetButtonDown("Jump"))
{
animation.Play("Jump");
}
}
The animation type is Generic, the root node is Armature, and my animations are Walk and Jump. If anyone can tell me what I am doing wrong or how this can be fixed I would very much appreciate it. Thank you.
Have you tried using GetKeyDown(KeyCode.a) or putting a Debug.Log(“a button was pressed”) in to be sure that these are even being called?
Also, are there any errors / is the script attached to a transform with an animation component?
GetKeyDown(KeyCode.a) did not work and the only thing I’m getting in the console now is:
[mecanim]: BindSkeleton: cannot find Transform ‘default’
I am assuming this is the issue yet I do not know what it means. As for the transform being attached to the animation component I am utterly confused as to what exactly I am supposed to attach it to. I understand I am supposed to attach it to the transform but I am oblivious as to what the transform would be. In the order I have in the Hierarchy it is, starting from the parent, I have “First Person Controller < Player < player(Mesh) and Armature” Armature then leads to “root” and so on.