using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GameManager : MonoBehaviour {
private float maxYRotation = 120;
private float minYRotation = 0;
private float maxXRotation = 60;
private float minXRotation = 0;
public GameObject obj;
private void Update(){
//鼠标坐标与屏幕的比例
float xPosPrecent = Input.mousePosition.x / Screen.width;
float yPosPrecent = Input.mousePosition.y / Screen.height;
//鼠标在轴上旋转的角度
float xAngle = -Mathf.Clamp(yPosPrecent * maxXRotation, minXRotation, maxXRotation) + 15;
float yAngle = Mathf.Clamp(xPosPrecent * maxYRotation, minYRotation, maxYRotation) - 60;
obj.transform.eulerAngles = new Vector3(xAngle, yAngle, 0);
}
}
备注:利用鼠标与屏幕的位置比进行更改物体的欧拉角。