//控制射击的方向
public void ShootDirection()
{
Vector3 worldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition); //获取鼠标的世界坐标
worldPoint = new Vector3(worldPoint.x, worldPoint.y, transform.position.z); //设置世界坐标
Vector3 pos = worldPoint - transform.position; //获取向量坐标的差值的向量
float angle = Vector3.Angle(Vector3.up, pos); //设置偏移角度
if (worldPoint.x>transform.position.x)
{
angle = -angle;
}
transform.eulerAngles = new Vector3(0, 0, angle); //使用欧拉角变化其位置方向
}
时间: 2024-10-15 07:06:16