unity 漫游相机

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class test_input : MonoBehaviour {
    string message;
    void Move(){
        var inputMid = Input.GetKey (KeyCode.Mouse2);
        var inputX = Input.GetAxis ("Mouse X");
        var inputY = Input.GetAxis ("Mouse Y");
        if (inputMid) {
            this.transform.Translate(new Vector3 (0f, -inputY, 0f));
            this.transform.Translate(new Vector3 (-inputX, 0f, 0f));
        }
    }
    void ChangeRay(){
        var inputX = Input.GetAxis ("Horizontal");
        var inputY = Input.GetAxis ("Vertical");
        this.transform.Rotate(new Vector3 (0f, inputX, 0f));
        this.transform.Rotate(new Vector3 (-inputY, 0f, 0f));
    }
    void ChangeSize(){
        var delteSize = Input.GetAxis ("Mouse ScrollWheel");
        var Size = this.GetComponent ().orthographicSize;
        Size = Size -delteSize*10;
        this.GetComponent ().orthographicSize = Size;
    }
    void changeDis(){
        var distance = Input.GetAxis ("Mouse ScrollWheel");
        this.transform.position = this.transform.position + this.transform.rotation * new Vector3 (0f, 0f, distance*10.0f);
        if (this.transform.position.y > 50.0f) {
            this.GetComponent ().orthographic = true;

        }else {
            this.GetComponent ().orthographic = false;
        }
    }
    void Update () {
        Move ();
        ChangeSize ();
        ChangeRay ();
        changeDis ();
        message = Input.mousePosition.x + "," + Input.mousePosition.y + "," + Input.mousePosition.z;
    }
    void OnGUI(){
        GUILayout.TextArea (message, 100);
    }
}

你可能感兴趣的:(unity 漫游相机)