Cant assign animation to script

So, i coded a basic script, that plays a walking animation when i move, and an idle animation, when i not moving. I think i coded it correctly, but i dont know. Here is the code i wrote:

var idleanim : Animation;

var walkanim : Animation;

function Start () {

}

function Update () {
//Input key "w"
if (Input.GetKeyDown("w")) {

}
if (Input.GetKeyUp("w")) {

}

//Input key "a"
if (Input.GetKeyDown("a")) {

}
if (Input.GetKeyUp("a")) {

}

//Input key "s"
if (Input.GetKeyDown("s")) {

}
if (Input.GetKeyUp("s")) {

}

//Input key "d"
if (Input.GetKeyDown("d")) {

}
if (Input.GetKeyUp("d")) {

}
}

But for some reason when i try to assign the animation to the script it won’t let me.
The animation is of course a .anim

All your code does is look for keypresses, but does nothing with animation...?

–

As perchik says your code isn't doing any animation code. You have to tell Unity to actually play animations. How depends on if you are using Mecanim or Legacy.

–

as perchik and huntsfromshadow says, yes i know how to play the animations, but thats not the problem. Read what i wrote ^^

–

1 Answer

1

i believe you working with legacy animation system.

check this:
http://docs.unity3d.com/412/Documentation/Manual/Animations40.html

and this:
http://docs.unity3d.com/412/Documentation/Manual/AnimationScripting40.html

thanks, i'll try it!

–