2016-05-23 44 views
0

我试图将它们添加到对象的数组后卸载资产,但它返回一个错误,说我只能清除一次一个,但我不知道该怎么做统一删除资产

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只能在个别资产使用,不能在游戏对象的/组件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); 

回答

0

卸载ObjectGameObject的线。铸造GameObject it = (GameObject)i;Resources.UnloadAsset(it);是完全不必要的,可能是问题。

Object[] tempItems = Resources.LoadAll("Inventory/Weapons",typeof(GameObject)); 
foreach (Object i in tempItems) 
{ 
    GameObject it = (GameObject)i; 
    Debug.Log(it); 
    itemList.Add(it); 
    Debug.Log(itemList.Count); 
} 

foreach (Object i in tempItems) 
{ 
    Resources.UnloadAsset(i); 
} 

我也建议你使用大写'O'的对象。不要认为它会有所作为,但只是在案件中。

+0

使用大写o的对象返回兼容性错误,同样使用unloadAsset建议返回相同的错误 – Sniffle6

+0

Object'是'UnityEngine.Object'和'object'之间的歧义参考 – Sniffle6

+0

@ Sniffle6修改了我的答案。再看一遍。如果出现错误,请写下您从中获取错误的代码行。 – Programmer