【发布时间】:2014-01-31 02:48:56
【问题描述】:
我正在制作游戏。我搜索对象中的所有子组件并从中创建一个列表,然后删除第一个条目,因为我不想要它。当我尝试删除第一个条目时发生错误。 google 上似乎没有这方面的内容,一切都是如何使它成为只读的。
我收到此错误:
NotSupportedException: Collection is read-only
System.Array.InternalArray__RemoveAt (Int32 index) (at /Users/builduser/buildslave/monoAndRuntimeClassLibs/build/mcs/class/corlib/System/Array.cs:147)
(wrapper managed-to-managed) UnityEngine.Transform[]:System.Collections.Generic.IList`1.RemoveAt (int)
PlayerEquipper.Start () (at Assets/PlayerEquipper.cs:27)
这是我的代码:
private IList<Transform> characterChilds = new List<Transform>();
private IList<Transform> armorChilds = new List<Transform>();
private IList<Transform> glovesChilds = new List<Transform>();
private IList<Transform> bootsChilds = new List<Transform>();
void Start()
{
characterChilds = new List<Transform>();
characterChilds = transform.GetComponentsInChildren<Transform>();
Debug.Log(characterChilds[0]);
characterChilds.RemoveAt(0);
Debug.Log(characterChilds[0]);
}
【问题讨论】: