zoukankan      html  css  js  c++  java
  • 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);
            }
    
        }
    }
  • 相关阅读:
    鼠标事件:
    各种坑记录
    Go学习笔记
    Scala学习笔记-7-代码片段
    Go学习笔记
    NIO学习笔记
    Redis常用操作
    docker & k8s 笔记
    Node常用笔记
    Maven常用笔记
  • 原文地址:https://www.cnblogs.com/k5bg/p/15157555.html
Copyright © 2011-2022 走看看