无法从'UnityEngine.GameObject'转换为'System.Predicate<UnityEngine.GameObject>'



我正在尝试查找列表项的索引,但无法使其工作。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ChunkLoader : MonoBehaviour
{
public GameObject[] screens = {};
public GameObject PlrSceen;
public int chunk_index;
// Start is called before the first frame update
void Start()
{
chunk_index = screens.FindIndex(screens,PlrScreen);
}
// Update is called once per frame
void Update()
{

}
}

Array.FindIndex需要检查谓词。这意味着您必须传递一个要调用的方法或lambda。谓词是一种方法,它传递参数T并返回布尔。

就是一个例子

chunk_index = screens.FindIndex(screens, go => go == PlrScreen);

然而,我建议不要这样做。您可以改用IndexOf,因为它会检查对象,而不是评估谓词。

最新更新