GameObject tempQie = Resources.Load(elementPrefabName) as GameObject;//通过prefab获取gameobject
GameObject tempQie2 = (GameObject)GameObject.Instantiate(tempQie);//在游戏场景中添加prefab
tempQie2.transform.position = position;
tempQie2.name = elementName;
tempQie2.AddComponent<BoxCollider2D>();//添加BoxCollider2D
tempQie2.GetComponent<BoxCollider2D>().center =new Vector2(0f,0f);
tempQie2.GetComponent<BoxCollider2D>().size = new Vector2(0.32f, 0.32f);
unity3d 代码动态添加,修改BoxCollider2D
最新推荐文章于 2024-10-03 19:15:00 发布