Can someone please give me an example of how to use this? I keep getting an error that “GetClipCount is not a member of UnityEngine.AnimationState”.
My goal is to play my “gun aim” animation until I have reached the last clip of the animation, and then to not call that animation again so that I freeze the gun aiming in it’s last animation frame until I have released the aim button.
Maybe there is a better way to do this, but it still would be nice to know how to use GetClipCount();
private var aimClipCount : int = 0;
function Start() {
//....
var aimClip = animation["aim"];
aimClipCount = aimClip.GetClipCount(); // error here
}
function QueryInputState() {
//....
if (Input.GetButton("Aim")) {
inputMode = inputModeType.AIM;
}
if (Input.GetButtonUp("Aim")) {
inputMode = inputModeType.WALK;
aimClipCount = aimClip.GetClipCount(); // error here
}
}
function Update() {
QueryInputState();
switch(inputMode) {
//....
case inputModeType.AIM:
if (aimClipCount) {
animation.Blend("aim",0.5,0.0);
aimClipCount--;
}
break;
}
}
It will teach you to put different animation clips on different layers with different blend weights. Then you can just call the individual animations and let the engine play them, blend them, clamp them if needed and so on.
Essentially you want to setup the aim animation clip on a higher layer than others, give it a decent blend weight, probably mark it as WrapMode.ClampForever then just call animation.CrossFade(“aim”) when aiming and animation.Crossfade(“walk”) when walking and so on.