Unity学习笔记 1.初试脚本

下载源码 UnityPackage

访问组件           GetComponent-<组件名>().组件属性

查找指定对象    GameObject.Find()

移动对象           TransFrom.Translate()

重力(刚体组件)  Rigidbody


1.效果


2.脚本

    public int num = 120;

    private Rigidbody rb;

    private GameObject red;
    private GameObject yellow;

    void Start()
    {
        rb = GetComponent<Rigidbody>();
        rb.useGravity = true;

        red = GameObject.Find("red");
        yellow = GameObject.Find("yellow");
    }

    void Update()
    {
        // 让红色方块向前移动
        red.GetComponent<Transform>().Translate(0, 0, 0.01f);

        // 让黄色方块向右移动
        yellow.GetComponent<Transform>().Translate(0.01f, 0, 0);

        // 让黄色方块转起来
        yellow.GetComponent<Transform>().Rotate(10f, 0, 0);


        //if (num % 2 == 0)
        //{
        //    Debug.Log(num + "是偶数");
        //}
        //else
        //{
        //    Debug.Log(num + "是奇数");
        //}
    }

 

                

相关推荐

  1. unity学习1)——控件与脚本的入门

    2024-03-20 21:06:03       42 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-20 21:06:03       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-20 21:06:03       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-20 21:06:03       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-20 21:06:03       20 阅读

热门阅读

  1. Android AMS——进程优先级更新(二十)

    2024-03-20 21:06:03       22 阅读
  2. FreeRTOS 简介

    2024-03-20 21:06:03       19 阅读
  3. 【Docker】常用命令 docker images

    2024-03-20 21:06:03       20 阅读
  4. 绘制虚线圆角矩形的Flutter小部件

    2024-03-20 21:06:03       19 阅读
  5. 一个好用的前端工具包 - 百涂工具

    2024-03-20 21:06:03       18 阅读
  6. git教程编写初衷

    2024-03-20 21:06:03       20 阅读
  7. Leetcode 239 滑动窗口最大值

    2024-03-20 21:06:03       22 阅读