- Home /
Slow down an animation from Script - C#
I found in the Documentation a thing called AnimationState.speed, but when i try to utilise it, it doesn't seem to work, at all. (Could it be outdated?)
Im basically trying to achieve, from my script, when such and such equals this and that, make the Animation.name.speed change for whatever reason.
In the documentation we have this:
public class ExampleScript : MonoBehaviour { public Animation anim;
void Start()
{
// Walk backwards
anim["Walk"].speed = -1.0f;
// Walk at double speed
anim["Walk"].speed = 2.0f;
}
}
I've replicated it, and it doesn't seem to work.
For the sake of this Question, my animation name is "dwarfAttack" and I would like the speed to be reduced to half. (Can this be kept in a FixedUpdate? for example anim["dwarfAttack"].speed = myFloatVariable).
I'm also having the problem of not being able to get or find the animation clip I want to use, and for the life of me I cannot find how to grab it from script, such as anim = gameobject.GetComponent().Animation("dwarfAttack") I'm stumped here, and the documentation isn't clear for me
progress, I found that if i Get the animator component I can simply set ALL the animations to half, like so: anim.speed = 0,5f; However I still don't know how to get just the one animation from the animator