Unity 3 D第2課キーボード、マウスで物体を移動

4588 ワード

public class xuanzhuan : MonoBehaviour {



    // 

    public float MoveSpeed;// Use this for initialization

    void Start () {



    }

    

    // Update is called once per frame

    void Update () {

// 

        if(Input.GetKey(KeyCode.A)){

            transform.Translate(Vector3.left* MoveSpeed,Space.World);

        }

        if(Input.GetKey(KeyCode.D)){

            transform.Translate(Vector3.right* MoveSpeed,Space.World);

        }

        if(Input.GetKey(KeyCode.W)){

            transform.Translate(Vector3.up* MoveSpeed,Space.World);

        }

        if(Input.GetKey(KeyCode.S)){

            transform.Translate(Vector3.down* MoveSpeed,Space.World);

        }



        // 

        if(Input.GetMouseButton(0)){

            transform.Rotate(Vector3.down* MoveSpeed,Space.World);

        }

        // 

        if(Input.GetMouseButton(1)){

            transform.Rotate(Vector3.up* MoveSpeed,Space.World);

        }



        // 

        //Zoom out

        if (Input.GetAxis("Mouse ScrollWheel") <0)

        {

            if(Camera.main.fieldOfView<=100)

                Camera.main.fieldOfView +=2;

            if(Camera.main.orthographicSize<=20)

                Camera.main.orthographicSize +=0.5F;

        }

        //Zoom in

        if (Input.GetAxis("Mouse ScrollWheel") > 0)

        {

            if(Camera.main.fieldOfView>2)

                Camera.main.fieldOfView-=2;

            if(Camera.main.orthographicSize>=1)

                Camera.main.orthographicSize-=0.5F;

        }



        

    }

}