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

时间:2022-07-28
本文章向大家介绍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,有效率问题。。。