【发布时间】:2016-05-24 03:12:26
【问题描述】:
我试图在将资产添加到对象数组后卸载它们,但它返回一个错误,说我一次只能删除一个,但我不知道该怎么做
object[] tempItems = Resources.LoadAll("Inventory/Weapons");
foreach (object i in tempItems)
{
GameObject it = (GameObject)i;
Debug.Log(it);
itemList.Add(it);
Debug.Log(itemList.Count);
}
foreach (object i in tempItems)
{
GameObject it = (GameObject)i;
Resources.UnloadAsset(it);
}
UnloadAsset 只能用于单个资产,不能用于 GameObject 的/组件或 AssetBundles
我正在使用
UnityEngine.Object[] tempItems = Resources.LoadAll("Inventory/Weapons");
foreach (UnityEngine.Object i in tempItems)
{
GameObject it = (GameObject)i;
Debug.Log(it);
itemList.Add(it);
Debug.Log(itemList.Count);
}
foreach (UnityEngine.Object i in tempItems)
{
Resources.UnloadAsset(i);
}
但我仍然收到错误
UnloadAsset may only be used on individual assets and can not be used on GameObject's / Components or AssetBundles
这是错误所在的行
Resources.UnloadAsset(i);
【问题讨论】: