public void Start() { currentState = HumanoidStateType.Idle; RotationMode = RotationType.MovementRelative; fallClip = loadAudioSource(fallSound); walkClip = loadAudioSource(walkSound); walkClip.loop = true; walkClip.Play(); walkClip.Pause(); }
public void StatusUpdate() { Rigidbody mover = character.GetComponent <Rigidbody>(); if (Jump) { if (currentState != HumanoidStateType.Jumping && currentState != HumanoidStateType.Freefalling) { if (isAny(HumanoidStateType.Running, HumanoidStateType.Idle)) { currentState = HumanoidStateType.Jumping; mover.velocity = mover.velocity + new Vector3(0, 60, 0); playClip(jumpSound); walkClip.Pause(); } } } Jump = false; if (mover.velocity.y < -0.3f && currentState != HumanoidStateType.Freefalling) { currentState = HumanoidStateType.Freefalling; fallSpeed = 0; fallClip.volume = -0.3f; fallClip.Play(); } else if (currentState == HumanoidStateType.Freefalling) { if (isClimbing) { currentState = HumanoidStateType.Climbing; fallClip.Stop(); } else { walkClip.Pause(); if (Mathf.Approximately(mover.velocity.y, 0)) { currentState = HumanoidStateType.Landed; fallClip.Stop(); if (fallSpeed > 0.1) { float volume = Mathf.Clamp((fallSpeed - 50f) / 110f, 0, 1); playClip(landSound, volume); } fallSpeed = 0; } else { fallClip.volume += Time.deltaTime; fallSpeed = Mathf.Max(Mathf.Abs(mover.velocity.y), fallSpeed); } } } else if (currentState != HumanoidStateType.Jumping) { if (isClimbing) { currentState = HumanoidStateType.Climbing; walkClip.Pause(); } else { if (currentState == HumanoidStateType.Climbing) { if (mover.velocity.y < 0.05f) { currentState = HumanoidStateType.Freefalling; } } else { float movementSpeed = cancelY(mover.velocity).magnitude; if (movementSpeed > 0.1) { currentState = HumanoidStateType.Running; walkClip.UnPause(); walkClip.pitch = movementSpeed / 8; } else { walkClip.Pause(); currentState = HumanoidStateType.Idle; } } } } else if (mover.velocity.y < 0.05f) { currentState = HumanoidStateType.Freefalling; } }