1. 程式人生 > >鏡頭變換01_U3D_讓camera上下左右移動和拉遠拉近

鏡頭變換01_U3D_讓camera上下左右移動和拉遠拉近

void ScrollScens()//螢幕拉遠拉近
    {
        if ( Mathf.Abs( Input.GetAxis("Mouse ScrollWheel"))>0.01f)
        {
           
            float distance = offset.magnitude;
            distance -=(Input.GetAxis("Mouse ScrollWheel"));
            print(distance);
            offset = offset.normalized * distance;
        }
    }


    void camera()//螢幕圍繞player水平旋轉//圍繞自己的x轉
{ transform.RotateAround(playerTransform.position, Vector3.up, Input.GetAxis("Mouse X")); //螢幕圍繞player水平旋轉 Vector3 pos = transform.position;//限制攝像機x的旋轉(0,80) Quaternion ros = transform.rotation; transform.RotateAround(playerTransform.position, transform.right, -Input.GetAxis("Mouse Y"));//圍繞自己的x轉
float x = transform.eulerAngles.x;//接下來本來是要衝出80的值 可衝出一點就又變回原形 if (x<10||x>80) { transform.position = pos; transform.rotation = ros; }