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

            }
        }
    }

     

  • 相关阅读:
    127.0.0.1(转) Anny
    轮岗开发后再看测试(转) Anny
    如何做好功能测试的方法(转) Anny
    Search Framework: Search Result checklist(转) Anny
    What is a Private IP Address(转) Anny
    Private IP Addresses(转) Anny
    公共模式资源库链接 Anny
    What is Dynamic DNS? Anny
    随机数产生
    tomcat源码阅读_代码篇4
  • 原文地址:https://www.cnblogs.com/li-yan-long/p/14122403.html
Copyright © 2020-2023  润新知