//不要加后缀名,和Resources, //如:路径"Resources/effect/building/Altar.prefab", //那么写成"effect/building/Altar" //把资源加载到内存中 GameObject prefab = (GameObject)Resources.Load("effect/building/Altar"); if (prefab) { //用加载得到的资源对象,实例化游戏对象,实现游戏物体的动态加载 GameObject obj = GameObject.Instantiate(prefab) as GameObject; if (obj) { obj.name = "xxxxxxxxxxx"; } }如果是创建NGUI ui预制物的话:
GameObject obj =NGUITools.AddChild(NGUIRoot.Instance.gameObject, prefab);