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);
    }

 

  }

}

posted @ 2017-09-01 16:19  痴王  阅读(6429)  评论(1编辑  收藏  举报