unity5.x Translate平移移动 以及GetComponent获取组件

    xiaoxiao2021-03-25  124

    在unity5.x中可以使用 Translate来移动某一个游戏对象,如下:

    m_cube.transform.Translate(Vector3.up)

    此代码使m_cube向上移动,其中,vector3.up是向上移动的意思,直接可以使用vector3或者vector2调用。

    在unity5.x中我们可以使用GetComponent来获取到组件,如下为添加2d刚体组建:

    this.gameObject.GetComponent<Rigidbody2D>()

    注意,尽量少用GetComponent,有效率问题。。。

    转载请注明原文地址: https://ju.6miu.com/read-6878.html

    最新回复(0)