unity3d 代码动态添加,修改BoxCollider2D

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)