美文网首页
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 漫游相机

  • Unity商店里的免费好用资源

    Unity 资源列表: 相机类: RTScamera : Unity商店里最好的相机插件资源。 EZCamera ...

  • laya3d界面显示黑屏

    unity相机allow hdr 属性改成false

  • Unity 相机 自建相机

    简介:Scene相机在最终的程序中是没有任何作用的,在Unity中大部分情况下我们最终用到的都是自己创建的相机,由...

  • Unity 相机 Scene 相机

    简介:Unity提供了相机这种物体,来进行结果渲染,我们到目前为止一直操作的是 Scene 窗口,这个窗口内看见的...

  • Unity 相机 多相机操作

    简介:Unity中允许同时存在多个相机,我们本节来讲解一下如何处理多个相机同时存在的状况版本:Unity2019....

  • Unity抓取相机截图/抓取屏幕截图

    Unity抓取相机截图/抓取屏幕截图 抓取相机截图 思路 在项目中,我们会遇到需要抓取相机截图,然后作为UI背景的...

  • layabox相机问题

    1.laya正交模式相机,不支持unity相机正交模式Size属性,会导致适配问题2.laya相机的遮挡剔除有问题...

  • 一、视角控制:虚拟相机控制视角

    在2018版本以上后,unity集成了虚拟相机插件,利用插件可以相机做跟随,注视,限制区域,已经轨道相机,镜头切换...

  • ShaderLab中的一些表格

    Unity内置变换矩阵变量 相机参数矩阵及一些变量 ShaderLab属性类型和CG变量类型的关系 Unity中一...

网友评论

      本文标题:unity 漫游相机

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