List.FindIndex
How works FindIndex?
public class FRef : MonoBehaviour {
string player_n;
public List<Prop> p = new List<Prop>();
int idx;
void Start()
{
idx = p.FindIndex(IsAlive);
Debug.Log(p[idx].name);
}
bool IsAlive(Prop stats)
{
return stats.health == 100;
}
}
And class.cs:
using UnityEngine;
using System.Collections;
using System;
public class Classes {
}
[Serializable]
public class Prop
{
public string name;
public int health;
}
I understood what this code does but I was wondering about "FindIndex". It is very strange. Please help.
Comment
The documentation is your friend next time : https://msdn.microsoft.com/en-us/library/0k601hd9(v=vs.110).aspx
Answer by Tourist · Feb 23, 2017 at 08:27 AM
FindIndex will scan a collection until the predicate (callback given as parameter) returns true.
In that case, it will return the first element of p where IsAlive returns true for it.
Your answer
Follow this Question
Related Questions
Technically Match 3 but not really 0 Answers
Method Group 1 Answer
Load Scene Unity by Application.LoadLevelAsync 0 Answers
How can i pass a method like a parameter Unity3d C#? 3 Answers