Hi, I’m trying to add new states to 3rd Person Character Controller but I have some problems, all the animation are working but when I press my “Interact” button nothing happens
function Update(){
if(Input.GetButtonDown("Interact")){
_characterState = CharacterState.Interacting;
}
UpdateSmoothedMovementDirection();
// Apply gravity
// - extra power jump modifies gravity
// - controlledDescent mode modifies gravity
ApplyGravity ();
// 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.Idle || controller.velocity.sqrMagnitude < 0.1 _characterState != CharacterState.Interacting){
_characterState = CharacterState.Idle;
_animation.CrossFade(idleAnimation.name);
}
if(_characterState == CharacterState.Running){
_animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, runMaxAnimationSpeed);
_animation.CrossFade(runAnimation.name);
}
if(_characterState == CharacterState.Trotting){
_animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, trotMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
if(_characterState == CharacterState.Walking){
_animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0, walkMaxAnimationSpeed);
_animation.CrossFade(walkAnimation.name);
}
if(_characterState == CharacterState.Interacting){
_animation[walkAnimation.name].speed = walkMaxAnimationSpeed;
_animation.CrossFade(walkAnimation.name);
}
//UNITY'S ANIMATION CODE
/*
if(controller.velocity.sqrMagnitude < 0.1) {
_characterState = CharacterState.Idle;
_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);
}
else if(_characterState == CharacterState.Interacting){
Debug.Log("BlaBla");
_animation[walkAnimation.name].speed = jumpAnimationSpeed;
_animation.CrossFade(jumpPoseAnimation.name);
}
}
*/
}
// ANIMATION sector
// Set rotation to the move direction
if(IsGrounded()){
transform.rotation = Quaternion.LookRotation(moveDirection);
}
else{
var xzMove = movement;
xzMove.y = 0;
if(xzMove.sqrMagnitude > 0.001){
transform.rotation = Quaternion.LookRotation(xzMove);
}
}
}
Can someone help me?