int floorMask; // 自动寻路层 void Awake() { floorMask = LayerMask.NameToLayer("Floor"); } void Turning() { Ray camRay = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit floorHit; if (Physics.Raycast(camRay, out floorHit, floorMask)) { Vector3 playerToMouse = floorHit.point - transform.position; playerToMouse.y = 0; Quaternion newRotation = Quaternion.LookRotation(playerToMouse); playerRigidbody.MoveRotation(newRotation); } }
时间: 2024-10-13 03:38:40