Unity学习笔记 1.初试脚本

下载源码 UnityPackage

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

查找指定对象 GameObject.Find()

移动对象 TransFrom.Translate()

重力(刚体组件) Rigidbody


1.效果


2.脚本

cs 复制代码
    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 + "是奇数");
        //}
    }
复制代码
相关推荐
齐生12 天前
iOS 知识点 - 渲染机制、动画、卡顿小集合
笔记
用户962377954482 天前
VulnHub DC-1 靶机渗透测试笔记
笔记·测试
齐生13 天前
iOS 知识点 - IAP 是怎样的?
笔记
tingshuo29174 天前
D006 【模板】并查集
笔记
tingshuo29175 天前
S001 【模板】从前缀函数到KMP应用 字符串匹配 字符串周期
笔记
西岸行者10 天前
学习笔记:SKILLS 能帮助更好的vibe coding
笔记·学习
starlaky10 天前
Django入门笔记
笔记·django
勇气要爆发10 天前
吴恩达《LangChain LLM 应用开发精读笔记》1-Introduction_介绍
笔记·langchain·吴恩达
悠哉悠哉愿意10 天前
【单片机学习笔记】串口、超声波、NE555的同时使用
笔记·单片机·学习
勇气要爆发10 天前
吴恩达《LangChain LLM 应用开发精读笔记》2-Models, Prompts and Parsers 模型、提示和解析器
android·笔记·langchain