Transform---將某物體旋轉至鼠標位置

/// <summary>
    /// 讓某物體轉角到鼠標點擊的位置
    /// </summary>
    /// <param name="RotateGO">需要轉角的那個物體</param>
    public static void  RotateToMouseClick(Transform RotateGO)
    {
        Vector3 mousePos = Input.mousePosition;
        mousePos = Camera.main.ScreenToWorldPoint(mousePos);
        Vector2 targetDir = mousePos - RotateGO.position;
        float angle = Vector2.Angle(targetDir, Vector3.up);
        if (mousePos.x > RotateGO.position.x)
            angle = -angle;
        RotateGO.eulerAngles = new Vector3(0, 0, angle);

    }



某個點旋轉某個角度後延某個方向運動運動十米

Vector3 newPos = this.transform.rotation * new Vector3(10f, 0f, 0f);

發佈了77 篇原創文章 · 獲贊 8 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章