zoukankan      html  css  js  c++  java
  • Unity基础(四):实现镜头的旋转,上下左右前后移动

    首先你要新建一个脚本,我这里是用c#,然后编写下面代码,最后将写好的c#脚本附加到主相机上。

    using UnityEngine;
    using System.Collections;

    public class Fashe:MonoBehaviour{

      void start(){}  

      void update(){

        float x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;//左右移动

        float z = Input.GetAxis("Vertical") * Time.deltaTime * speed;//前后移动

         transform.Translate(x,0,z);//相机的移动

        //旋转功能

        if (Input.GetKey(KeyCode.Q))//这个 表示如果键盘上输入Q则返回 true
        {
          transform.Rotate(0, -25 * Time.deltaTime, 0, Space.Self);//transform表示该物体下的transform组件,Rotate()表示旋转角度,前三个参数表示 X,Y.Z轴上的旋    转角度,最后一个参数表示围绕自身旋转。下面的也是类似!
        }
        if (Input.GetKey(KeyCode.E))
        {
        transform.Rotate(0, 25 * Time.deltaTime, 0, Space.Self);
        }
        //上下移动镜头
        if (Input.GetKey(KeyCode.H))
        {
          transform.Translate(0, 3 * Time.deltaTime, 0);
        }
        if (Input.GetKey(KeyCode.N))
        {
          transform.Translate(0, -3 * Time.deltaTime, 0);
        }

      }

    }

  • 相关阅读:
    Ellipsis 的升级版 line-clamp
    Angular7里面实现 debounce search
    闭包、迭代器
    Day10 函数的进阶
    函数
    文件的操作
    Day 07基础数据补充、set、深浅拷贝
    小数据池,编码和解码
    字典
    列表、元祖的操作
  • 原文地址:https://www.cnblogs.com/chiwang/p/7463767.html
Copyright © 2011-2022 走看看