System.Collections无法引用

VS2019 无法添加引用System.Collections;
visual Studio community2019,unity,c#
点击添加引用,框架中并没有System.Collections;

进而去“管理解决方案的Nunet的程序包”查找下载,显示已经添加到Assembly-CSharp,但代码中仍然是灰色

img

你这个target是个gameobject类型吧,上面不是提示不包含childcount定义吗,只有transform类型下才有,正确的写法应该是:


 for (int i = 0; i < target.transform.childCount; i++)
            {
                target.transform.GetChild(i).gameObject.SetActive(false);
            }

需要看下这个Target是如何定义的,
以及你的报错信息文本都是什么

你截图的问题和System.Collections无法引用,没什么关系。问题原因是你的Target定义的是Gameobject类型,不能直接调用.childCount。你可以将Target定义转换为'Transform'类型,或者像1楼说的那样,先.transform然后在使用其属性和方法.childCount和·.GetChild(i)·