[英]Cannot convert from 'UnityEngine.GameObject' to 'System.Predicate<UnityEngine.GameObject>'
I am trying to find the index of a list item, but i can't get it to work.我正在尝试查找列表项的索引,但无法正常工作。
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
expects a predicate to check for. Array.FindIndex
需要一个谓词来检查。 This means you have to pass a method or lambda to be called.这意味着您必须传递一个方法或 lambda 才能被调用。 A Predicate is a method that gets passed a parameter T and returns a bool.
Predicate 是一种传递参数 T 并返回布尔值的方法。
An example would be一个例子是
chunk_index = screens.FindIndex(screens, go => go == PlrScreen);
However, I'd advise against that.但是,我建议不要这样做。 You could use
IndexOf
instead, as it checks for the object instead for evaluating a predicate.您可以改用
IndexOf
,因为它会检查 object 而不是评估谓词。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.