首页 > 学院 > 开发设计 > 正文

unity之动态添加组件

2019-11-06 08:34:38
字体:
来源:转载
供稿:网友

                    

  Transform[] abc = hit.collider.gameObject.transform.parent.GetComponentsInChildren<Transform>();// hit.collider.gameObject.GetComPonent<Transform>()和直接.transform的区别                for (int i = 0; i < 18;i++ )                {                    abc[i].gameObject.AddComponent<Rigidbody>();                    Destroy(abc[i].gameObject, 2);                }

                        GameObject.AddComponent  用这个函数改变运行中的物体的行为。你可以用传递脚本名称的方法,把程序脚本加载给游戏内物体。

                        给每一个abc[i]添加Rigidbody组件


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表