Unity5.4 攝像機(jī)圍繞物體旋轉(zhuǎn)與方向操作

public Transform target;//獲取旋轉(zhuǎn)目標(biāo)

private void camerarotate() //攝像機(jī)圍繞目標(biāo)旋轉(zhuǎn)操作
    {
        transform.RotateAround(target.position, Vector3.up, speed*Time.deltaTime); //攝像機(jī)圍繞目標(biāo)旋轉(zhuǎn)
        var mouse_x = Input.GetAxis("Mouse X");//獲取鼠標(biāo)X軸移動
        var mouse_y = -Input.GetAxis("Mouse Y");//獲取鼠標(biāo)Y軸移動
        if (Input.GetKey(KeyCode.Mouse1))
        {
            transform.Translate(Vector3.left*(mouse_x*15f)*Time.deltaTime);
            transform.Translate(Vector3.up*(mouse_y*15f)*Time.deltaTime);
        }
        if (Input.GetKey(KeyCode.Mouse0))
        {
            transform.RotateAround(target.transform.position, Vector3.up, mouse_x*5);
            transform.RotateAround(target.transform.position, transform.right, mouse_y*5);
        }
    }

    private void camerazoom() //攝像機(jī)滾輪縮放
    {
        if (Input.GetAxis("Mouse ScrollWheel") > 0)
            transform.Translate(Vector3.forward*0.5f);


        if (Input.GetAxis("Mouse ScrollWheel") < 0)
            transform.Translate(Vector3.forward*-0.5f);
    }
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容