animation.GetCLipCount() example?

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;
  }
}

Thanks

-Raiden

GetClipCount returns the number of AnimationClips inside an Animation object.

The following line of code;

var aimClip = animation[“aim”];

returns an “AnimationClip”, which does NOT have the method GetClipCount, so the following is an error.

aimClipCount = aimClip.GetClipCount(); // error here

A proper usage of the method would be;

var HowManyAnimationsDoIHave = animation.GetClipCount();

Hope that helps,

Charles

Raiden,

I started to write a small example but then remembered there is a great sample project here;

http://unity3d.com/support/resources/example-projects/character-animation

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.

Charles

Thanks for the info Charles.

I was able to resolve my issue by simply toggling ClampModeForever on and off depending on if the “aim” button was pressed more than once.

Here’s just the pieces of code for that part:

private var areAiming : boolean = false; 
function Start() { 
  //.... 
  animation["aim"].layer = 9;
  animation["aim"].speed = 0.8;
  animation["aim"].wrapMode = WrapMode.ClampForever; 
} 

function QueryInputState() { 
  //.... 
   if (Input.GetButtonUp("Aim")) { 
     areAiming = (!areAiming) ? false : true;
    if (areAiming) {
	    animation["aim"].wrapMode = WrapMode.ClampForever;
	    inputMode = inputModeType.AIM;
    }
    else {
	    animation["aim"].wrapMode = WrapMode.Once;
	    inputMode = inputModeType.WALK;
    }
}

function Update() { 
  QueryInputState(); 
  switch(inputMode) { 
   //.... 
   case inputModeType.AIM: 
         animation.CrossFade("aim"); 
   break; 
  } 
}

I’ve still more to learn about animations, I know they can do so much more than what I am trying to accomplish, I’ll just have to keep at it.

Thanks

-Raiden