• unity脚本物体移动,旋转,属性可见性


    1.如下例子:在unity中跑一下就能测出结果,点击鼠标,按住w键,S键

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    //在unity组件列表中的名字
    [AddComponentMenu("Demoxxxx")]
    public class Demo02 : MonoBehaviour
    {
        //私有属性,但加上[SerializeField]描述后unity中可见。
        [SerializeField]
        private float speed;
    
        void Start()
        {
            Debug.Log("Hello World");//在unity控制台中打印信息
        }
        void Update()
        {
            if (Input.GetKey(KeyCode.W)) {//监听 W 键
                // Time.deltaTime表示:保证一定的帧率
                this.transform.Translate(new Vector3(0F, 0F, 20F) * Time.deltaTime , Space.World);//像指定方向移动
            } else if (Input.GetKey(KeyCode.S)) {
                this.transform.Translate(new Vector3(0F, 0F, -20F) * Time.deltaTime, Space.World);//像指定方向移动
            }
            if (Input.GetMouseButtonDown(0)) {//鼠标右键,点一下动一下
                this.transform.Rotate(new Vector3(0F, 0F, 100F) * Time.deltaTime, Space.World);//旋转
            } else if (Input.GetMouseButtonDown(1)) {//鼠标左键,点一下动一下

            //当前对象围绕指定物体旋转,Camera.main.transform.position当前摄像头,Vector3.up方向,速度
            this.transform.RotateAround(Camera.main.transform.position, Vector3.up, 1000F * Time.deltaTime);

            }
        }
    }

     

  • 相关阅读:
    强弱类型 静态语言 动态语言 || 脚本语言
    mysql版本升级问题处理
    word
    IntelliJ IDEA 插件
    dubbo
    spring源码构建
    zookeeper 本地多线程模拟分布式事务控制及配置中心
    一次性关闭所有的Activity
    可能以后用得到得东西
    Thread.sleep还是TimeUnit.SECONDS.sleep
  • 原文地址:https://www.cnblogs.com/li-yan-long/p/14122403.html
Copyright © 2020-2023  润新知