using UnityEngine;
public class RotateTest : MonoBehaviour
{
/// <summary>
/// 鼠标位置
/// </summary>
private Vector3 inputRotation;
private Vector3 tempVector;
private Vector3 tempVector2;
void Update()
{
FindPlayerInput();
//方法一
//transform.LookAt(new Vector3(inputRotation.x, transform.position.y, inputRotation.z));
//方法二
transform.rotation = Quaternion.LookRotation(inputRotation);
transform.eulerAngles = new Vector3(0, transform.eulerAngles.y + 180, 0);
}
/// <summary>
/// 查找鼠标位置
/// </summary>
void FindPlayerInput()
{
tempVector2 = new Vector3(Screen.width * 0.5f, 0, Screen.height * 0.5f);
tempVector = Input.mousePosition;
tempVector.z = tempVector.y;
tempVector.y = 0;
inputRotation = tempVector - tempVector2;
}
}