美文网首页
unity 漫游相机

unity 漫游相机

作者: 繁木成林 | 来源:发表于2017-12-15 00:44 被阅读55次
    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<Camera> ().orthographicSize;
            Size = Size -delteSize*10;
            this.GetComponent<Camera> ().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<Camera> ().orthographic = true;
    
            }else {
                this.GetComponent<Camera> ().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 漫游相机

          本文链接:https://www.haomeiwen.com/subject/elqrwxtx.html