《Unity3d-控制槍口的朝向代碼》


//控制射擊的方向
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); //使用歐拉角變化其位置方向
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM