简体   繁体   English

无法从“UnityEngine.GameObject”转换为“System.Predicate”<unityengine.gameobject> '</unityengine.gameobject>

[英]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.

相关问题 无法将类型“UnityEngine.Transform”转换为“UnityEngine.GameObject” - Cannot convert type `UnityEngine.Transform' to `UnityEngine.GameObject' 无法将类型“UnityEngine.GameObject”隐式转换为“GameObject” - Cannot implicitly convert type 'UnityEngine.GameObject' to 'GameObject' 如何将类型“int”转换为“unityengine.gameobject”? - How to convert type 'int' to 'unityengine.gameobject'? 无法将类型“UnityEngine.GameObject”隐式转换为“GameMaster”? - Cannot implicitly convert type 'UnityEngine.GameObject' to 'GameMaster'? 无法将类型&#39;Vuforia.Anchor&#39;隐式转换为&#39;UnityEngine.GameObject&#39; - Cannot implicitly convert type `Vuforia.Anchor' to 'UnityEngine.GameObject' 尝试实例化 object 时无法将类型“UnityEngine.GameObject”隐式转换为“UnityEngine.Vector2” - Cannot implicitly convert type 'UnityEngine.GameObject' to 'UnityEngine.Vector2'" While trying to Instantiate an object foreach语句无法遍历UnityEngine.GameObject类型的变量 - foreach statement cannot ooperate on variables of type UnityEngine.GameObject SerializationException:类型UnityEngine.GameObject未标记为Serializable - SerializationException: Type UnityEngine.GameObject is not marked as Serializable UnityEngine.GameObject与Generic.List <UnityEngine.GameObject> - UnityEngine.GameObject vs. Generic.List<UnityEngine.GameObject> Unity C# 错误:(12,47):错误 CS1503:参数 2:无法从 &#39;System.Collections.Generic.List 转换<UnityEngine.GameObject> &#39; 浮&#39; - Unity C# error: (12,47): error CS1503: Argument 2: cannot convert from 'System.Collections.Generic.List<UnityEngine.GameObject>' to 'float'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM