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);
            }
    
        }
    }
  • 相关阅读:
    C语言之分支语句
    C语言之运算符与表达式
    C语言之数据类型④——中文字符
    独特的对象引用:this
    理解赋值“=”的含义
    编写类的 “模板”
    类的定义
    Java语言规范
    第一周总结
    定义常量
  • 原文地址:https://www.cnblogs.com/k5bg/p/15157555.html
Copyright © 2011-2022 走看看