0
\$\begingroup\$

I have created the walking and idle animation for my fps player. I've added a JavaScript script to access it, but when I run it and press button(w), it stops and says that the animation is not attached to the object.

When I drag the walking/idle animation and drop to that object, it creates an animation controller. Again I run it, still same error. I can't find where to attach the animation

Here's my script:

function Update () 
{
  if(Input.GetKeyDown("w"))
  {
    GetComponent.<Animation>().Play("walk_anim2", PlayMode.StopAll);
  }
  if(Input.GetKeyUp("w"))
  {
    GetComponent.<Animation>().Play("idle_anim2", PlayMode.StopAll);
  }
}

Where do I need to attach the animation?

enter image description here

\$\endgroup\$
5
  • 1
    \$\begingroup\$ Can you screencap the hierarchy where the relevant GameObject is and whatever the inspector is showing with this player selected? \$\endgroup\$
    – Foggzie
    Commented Dec 22, 2015 at 22:14
  • \$\begingroup\$ Is the animation controller that you are attaching the one with the animations in it? I have had this issue before when adding an animation controller it just creates an empty on instead. If that is the case simply copy your animations into that controller that is attached to your game object. \$\endgroup\$
    – Shaun
    Commented Dec 23, 2015 at 7:51
  • \$\begingroup\$ i've added the screenshot.... i can't understand.. hlp pls !!! \$\endgroup\$ Commented Jan 4, 2016 at 17:24
  • 1
    \$\begingroup\$ You have an Animator component attached but your script is asking for an Animation component. These are two different things. \$\endgroup\$
    – DMGregory
    Commented Jan 4, 2016 at 17:28
  • \$\begingroup\$ i've added the animation component too. but, that was also not working. anyway, what exactly i have to do right now? \$\endgroup\$ Commented Jan 4, 2016 at 17:40

1 Answer 1

2
\$\begingroup\$

You are using an Animator component but you are referencing Animation in your script. You can see in the error it says MissingComponent. You should use Animator component.

Here is the link for relevant API page: http://docs.unity3d.com/ScriptReference/Animator.html

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .