Hi
I have quite a few pre done animations ive brought over as part of the fbx for my player.
Im trying to set up the Shoot animation but for some reason i cant seem to get the layering right.
The Unity docs say to use WrapMode.once but then when i look at the animation in the Third Person controller for Jump/wal/run etc they use different.
Heres my current code modifications to the Third Person Controller Script
Variables
public var idleAnimation : AnimationClip;
public var walkAnimation : AnimationClip;
public var runAnimation : AnimationClip;
public var jumpPoseAnimation : AnimationClip;
public var ShootAnimation : AnimationClip;
public var FallAnimation : AnimationClip;
public var walkMaxAnimationSpeed : float = 0.75;
public var trotMaxAnimationSpeed : float = 1.0;
public var runMaxAnimationSpeed : float = 1.0;
public var jumpAnimationSpeed : float = 1.15;
public var landAnimationSpeed : float = 1.0;
public var ShootMaxAnimationSpeed : float = 1.0;
public var FallMaxAnimationSpeed : float = 1.0;
private var _animation : Animation;
Character State Function
enum CharacterState {
Idle = 0,
Walking = 1,
Trotting = 2,
Running = 3,
Jumping = 4,
Shooting = 5,
}
125Update Function125
function Update() {
if (Input.GetMouseButtonDown(1))
{
_characterState = CharacterState.Shooting;
}
if (!isControllable)
I used ClampForever and the animation goes and gets stuck
I used Once and the animation didnt go at all
I used loop and of course the animation just kept looping
I just want it to play every time i Click shoot and allow the animation to play before i can shoot again i guess
Please help!!
{
// kill all inputs if not controllable.
Input.ResetInputAxes();
}
if (Input.GetButtonDown ("Jump"))
{
lastJumpButtonTime = Time.time;
}
UpdateSmoothedMovementDirection();
// Apply gravity
// - extra power jump modifies gravity
// - controlledDescent mode modifies gravity
ApplyGravity ();
// Apply jumping logic
ApplyJumping ();
// Calculate actual motion
var movement = moveDirection * moveSpeed + Vector3 (0, verticalSpeed, 0) + inAirVelocity;
movement *= Time.deltaTime;
// Move the controller
var controller : CharacterController = GetComponent(CharacterController);
collisionFlags = controller.Move(movement);
// ANIMATION sector
if(_animation)
{
if(_characterState == CharacterState.Shooting)
{
_animation[ShootAnimation.name].speed = ShootMaxAnimationSpeed;
_animation[ShootAnimation.name].wrapMode = WrapMode.ClampForever;
_animation.CrossFade(ShootAnimation.name);
}
if(_characterState == CharacterState.Jumping)
{
if(!jumpingReachedApex) {
_animation[jumpPoseAnimation.name].speed = jumpAnimationSpeed;
_animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
_animation.CrossFade(jumpPoseAnimation.name);
} else {
_animation[jumpPoseAnimation.name].speed = -landAnimationSpeed;
_animation[jumpPoseAnimation.name].wrapMode = WrapMode.ClampForever;
_animation.CrossFade(jumpPoseAnimation.name);
}
}
else
{
if(controller.velocity.sqrMagnitude < 0.1) {
_animation.CrossFade(idleAnimation.name);
}
else
{
if(_characterState == CharacterState.Running) {
_animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, runMaxAnimationSpeed);
_animation.CrossFade(runAnimation.name);
}
else if(_characterState == CharacterState.Trotting) {
_animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, trotMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
else if(_characterState == CharacterState.Walking) {
_animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, walkMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
}
}
}