ArgumentException: GetComponent requires that the requested component ‘GameObject‘ derives from Mono

错误描述:ArgumentException: GetComponent requires that the requested component ‘GameObject‘ derives from Mono

英文翻译:GetComponent要求被请求的组件“GameObject”来自MonoBehaviour或component,或者是一个接口。

问题分析

这是在使用:GetComponent这类东西时会发生的问题

GameObject[] list=transform.GetComponentsInChildren<GameObject>();

因为对象不是GameObject,所以要使用Transform之类的对象作为目标。

我将它改为:

Transform[] list=transform.GetComponentsInChildren<Transform>();

就正常了,或者是你需要的其他类型。

—— 完 ——