Funtion called without parenthesis
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class Input_M : MonoBehaviour {
public List <Buttons> game_b = new List<Buttons>();
string s_name;
int index;
public bool Pressed(string but_name)
{
s_name = but_name;
index = game_b.FindIndex(IsName);
}
bool IsName(Buttons bu)
{
return bu.b_name == s_name;
}
}
Why is function "IsName" called without parenthesis? And it returns an integer because the funtion "FindIndex", the parameter is int. Why is that???
Answer by Nischo · Feb 22, 2017 at 11:24 AM
What you are seeing is not a called method, but a reference to a method. This effectively allows you to pass methods to other methods/objects and allow them to use that method. A Method can be stored for example in an Action, Func or Predicate. In this case, FindIndex takes your method, iterates over all elements in the list and calls your method for every object, passing it the element. If on any method call, your method returns true, FindIndex will stop iterating and return the Index of that element that returned true.
Thank you! You are awesome. Could you please give me an example with the console? Or a link for documentation. Please!
Your answer
![](https://koobas.hobune.stream/wayback/20220612111643im_/https://answers.unity.com/themes/thub/images/avi.jpg)