Unity Prefab(预制体)一次性循环10个会得到同样的

IEnumerator Test1() {
        for(int i = 0;i < 5;i++) {
            GameObject gb = (GameObject)Resources.Load("Prefabs/Image");
            gb.name = i.ToString() + "_cui";
            allMoveImages.Add(gb);
            yield return new WaitForSeconds(1);
        }
    }

上面会得到五个一模一样的,我想得到不一样的

 

 修改如下

 IEnumerator Test1() {
        for(int i = 0;i < 5;i++) {
            GameObject gb = (GameObject)Resources.Load("Prefabs/Image");
            gb.name = i.ToString() + "_cui";
            GameObject g = new GameObject(gb.name);
            allMoveImages.Add(g);
            yield return new WaitForSeconds(1);
        }
    }

 

posted on 2023-02-27 16:22  zqiang0803  阅读(84)  评论(0编辑  收藏  举报

导航