using System.Collections; using System.Collections.Generic; using UnityEngine; public class PlayerController : MonoBehaviour { public Animator anim; public CharacterController characterController; public float jumpPower; private Vector3 velocity; void Start() { anim = GetComponent(); characterController = GetComponent(); } void Update() { float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); anim.SetFloat("Speed", v, 0.2f, Time.deltaTime); anim.SetFloat("Turn", h, 0.2f, Time.deltaTime); velocity.y += Physics.gravity.y * Time.deltaTime; //在速度中增加重力 characterController.Move(velocity * Time.deltaTime); //將總和的速度加速到角色控制器 if (Input.GetButtonDown("Jump")) { velocity.y = Mathf.Sqrt(jumpPower * -2.0f * Physics.gravity.y); //計算初始垂直速度(Mathf.Sqrt = 計算一個數字的平方根) } } } // 這是 V1 版本