代码实现:
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMove : MonoBehaviour
{
private Camera mCamera;
// Start is called before the first frame update
void Start()
{
mCamera = transform.Find("PlayerCamera").GetComponent();
}
// Update is called once per frame
void Update()
{
float x = Input.GetAxisRaw("Mouse X");
float y = Input.GetAxisRaw("Mouse Y");
//鼠标x轴的偏移量,直接用来旋转人物的y轴
transform.Rotate(new Vector3(0, x, 0), Space.Self);
//鼠标y轴的偏移量,用来让相机绕着人物的x轴旋转
mCamera.transform.RotateAround(transform.position,transform.right,-y);
}
}