public class RotateScript : MonoBehaviour
{
// Start is called before the first frame update
public float speed = 1;
private Vector3 lastPostion;
public LayerMask whatIsGround;
void Start()
{
}
// Update is called once per frame
void Update()
{
//旋转方法一
//if (Input.GetMouseButtonDown(0))
//{
// lastPostion = Input.mousePosition;
//}
//else if (Input.GetMouseButton(0)) {
// Vector3 newPostion = Input.mousePosition;
// Vector3 potPoint = lastPostion - newPostion;
// lastPostion = newPostion;
// Quaternion rot = Quaternion.Euler(potPoint.y* speed, potPoint.x * speed,0);
// transform.rotation = rot * transform.rotation;
//}
//旋转方法二
Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
Debug.Log(ray);
RaycastHit hitInfo;
if (Physics.Raycast(ray, out hitInfo, 200, whatIsGround)) {
Vector3 target = hitInfo.point;
//target.y = transform.position.y;
transform.LookAt(target);
}
}
}