InvokeRepeating with parameters

Is it possible to do something like this:
InvokeRepeating(SearchForTarget(detectRange), 1, 1);

InvokeRepeating just takes a function name, no parameters. But…

I suppose detectRange is potentially different each time you call SearchForTarget. If so, you can move the logic for determining detectRange inside the SearchForTarget. That way, InvokeRepeating will do what you want.

Or, if you really need to have parameters, do

StartCoroutine(SearchForTargetRepeat(param1, param2,..., repeatRate));

where

IEnumerator SearchForTargetRepeat(param1, param2,..., repeatRate) {
    while(someCondition) {
        SearchForTarget(param1, param2, ...);
        yield return new WaitForSeconds(repeatRate);
    }
}

(This may be an old post but I was just having this same issue and so this answer is more for my future self …and it was never answered properly)

It might be best to add a separate function that calls your other function with parameters.

So something like ::

private void A(int a)
{
    Debug.Log("a = "+a);
}

private void B()
{
    A(Random.Range(0,1000);
}

private void C()
{
    InvokeRepeating("B",0,0);
}