IEnumerator WaitForAnimationPlayOver(string animationName, int attackstyle) { //Debug.Log(Time.time); playerstate.setAniState((int)(playerStateLinster.enum_ani_state.Attacking1 + attackstyle)); yield return(new WaitForSeconds(_animation[animationName].length)); playerstate.setAniState((int)playerStateLinster.enum_ani_state.NoAni); //Debug.Log(Time.time); //Debug.Log (_animation [animationName].length); }
void Awake() { moveDirection = transform.TransformDirection(Vector3.forward); playerstate = GameObject.FindWithTag("scriptObj").GetComponent <playerStateLinster> (); playerstate.setAniState(0); _animation = GetComponent <Animation>(); if (!_animation) { Debug.Log("The character you would like to control doesn't have animations. Moving her might look weird."); } /* * public var idleAnimation : AnimationClip; * public var walkAnimation : AnimationClip; * public var runAnimation : AnimationClip; * public var jumpPoseAnimation : AnimationClip; */ if (!idleAnimation) { _animation = null; Debug.Log("No idle animation found. Turning off animations."); } if (!walkAnimation) { _animation = null; Debug.Log("No walk animation found. Turning off animations."); } if (!runAnimation) { _animation = null; Debug.Log("No run animation found. Turning off animations."); } if (!jumpPoseAnimation && canJump) { _animation = null; Debug.Log("No jump animation found and the character has canJump enabled. Turning off animations."); } }
void Update() { if (!isControllable) { // kill all inputs if not controllable. Input.ResetInputAxes(); } if (Input.GetButtonDown("Jump")) { lastJumpButtonTime = Time.time; } if (playerstate.ani_stat == playerStateLinster.enum_ani_state.Attacking1) { //Debug.Log("control"); moveSpeed = 0; //isControllable =false; // return ; } UpdateSmoothedMovementDirection(); // Apply gravity // - extra power jump modifies gravity // - controlledDescent mode modifies gravity ApplyGravity(); // Apply jumping logic ApplyJumping(); // Calculate actual motion Vector3 movement = moveDirection * moveSpeed + new Vector3(0, verticalSpeed, 0) + inAirVelocity; movement *= Time.deltaTime; // Move the controller CharacterController controller = GetComponent <CharacterController>(); collisionFlags = controller.Move(movement); // ANIMATION sector if (_animation) { 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.1f) { _animation.CrossFade(idleAnimation.name); _characterState = CharacterState.Idle; } else { if (_characterState == CharacterState.Running) { _animation[runAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, runMaxAnimationSpeed); _animation.CrossFade(runAnimation.name); } else if (_characterState == CharacterState.Trotting) { _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, trotMaxAnimationSpeed); _animation.CrossFade(walkAnimation.name); } else if (_characterState == CharacterState.Walking) { _animation[walkAnimation.name].speed = Mathf.Clamp(controller.velocity.magnitude, 0.0f, walkMaxAnimationSpeed); _animation.CrossFade(walkAnimation.name); } } } } // ANIMATION sector // Set rotation to the move direction if (IsGrounded()) { transform.rotation = Quaternion.LookRotation(moveDirection); } else { Vector3 xzMove = movement; xzMove.y = 0; if (xzMove.sqrMagnitude > 0.001f) { transform.rotation = Quaternion.LookRotation(xzMove); } } // We are in jump mode but just became grounded if (IsGrounded()) { lastGroundedTime = Time.time; inAirVelocity = Vector3.zero; if (jumping) { jumping = false; SendMessage("DidLand", SendMessageOptions.DontRequireReceiver); } } int b = (int)_characterState; //Debug.Log (b); if (playerstate.ani_stat == playerStateLinster.enum_ani_state.Attacking1) { // Debug.Log("not set "); return; } playerstate.setAniState(b); }