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

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

m_cube.transform.Translate(Vector3.up)

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

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

this.gameObject.GetComponent<Rigidbody2D>()

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

猜你喜欢

转载自blog.csdn.net/a757291228/article/details/60884417