//添加
GameObject obj = new GameObject("cube");
obj.AddComponent<Rigidbody>();
//Tip 添加的组件也可以是脚本
//销毁
Destroy(obj.GetComponent<Rigidbody>());
通过代码给物体添加组件
最新推荐文章于 2023-12-25 15:08:15 发布
//添加
GameObject obj = new GameObject("cube");
obj.AddComponent<Rigidbody>();
//Tip 添加的组件也可以是脚本
//销毁
Destroy(obj.GetComponent<Rigidbody>());