添加組件和刪除組件代碼unity
代碼添加組件
gameObject.AddComponent ("FoobarScript");//最好使用類型方式,提交效率如typeof(Rigidbody)
注意沒有RemoveComponent()方法。如果你想去掉一個組件,可以使用Object.Destroy。
添加組件和刪除組件代碼
---
IEnumerator Start () {
this.gameObject.AddComponent(typeof(Rigidbody));
yield return new WaitForSeconds(0.5F);
Destroy(this.rigidbody);
}
---
gameObject.AddComponent ("FoobarScript");//最好使用類型方式,提交效率如typeof(Rigidbody)
注意沒有RemoveComponent()方法。如果你想去掉一個組件,可以使用Object.Destroy。
添加組件和刪除組件代碼
---
IEnumerator Start () {
this.gameObject.AddComponent(typeof(Rigidbody));
yield return new WaitForSeconds(0.5F);
Destroy(this.rigidbody);
}
---
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.