using System.Collections; using System.Collections.Generic; using UnityEngine; public class CameraMove : MonoBehaviour { public CharacterController CharacterController; [Header("Move")] public float Speed = 12f; public float Gravity = 20f; private Vector3 m_Velocity; private void Start() { try { CharacterController = GetComponent(); } catch { CharacterController = null; } Cursor.lockState = CursorLockMode.Locked; } void Update() { //平面移动 float x = Input.GetAxis("Horizontal"); float y = Input.GetAxis("Vertical"); Vector3 MoveDir = transform.right * x + transform.forward * y; CharacterController.Move(MoveDir * Speed * Time.deltaTime); //自由落体 m_Velocity.y -= Time.deltaTime * Gravity; CharacterController.Move(m_Velocity * Time.deltaTime); } }