Unity:镜头移动

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

public class CameraScript : MonoBehaviour
{
    public float speed = 5.0f;

    // Start is called before the first frame update
    void Start()
    {
        
    }

    // Update is called once per frame
    void Update()
    {
        //键盘移动镜头
        /*
        if ( Input.GetKeyDown(KeyCode.A) )
        {
            Debug.Log("k5");
        }
        */

        
        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))
        {
            transform.Rotate(0, -25 * Time.deltaTime, 0, Space.Self);
        }

        if (Input.GetKey(KeyCode.E))
        {
            transform.Rotate(0, 25 * Time.deltaTime, 0, Space.Self);
        }

        //上下移动镜头
        if (Input.GetKey(KeyCode.R))
        {
            transform.Translate(0, 3 * Time.deltaTime, 0);
        }

        if (Input.GetKey(KeyCode.F))
        {
            transform.Translate(0, -3 * Time.deltaTime, 0);
        }

    }
}
原文地址:https://www.cnblogs.com/k5bg/p/15157555.html