- Home /
InvokeRepeating with parameters
Is it possible to do something like this: InvokeRepeating(SearchForTarget(detectRange), 1, 1);
Answer by autowash · Nov 15, 2012 at 04:04 PM
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);
}
}
Answer by Nichathan · Aug 28, 2021 at 01:55 AM
(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);
}
Your answer
Follow this Question
Related Questions
How to create instance of ScriptableObject and pass its constructor a parameter? 6 Answers
How do I pass an Texture2D from one function to another? 1 Answer
Invoking does not work, but why? 1 Answer
What is the difference between InvokeRepeating & Invoke and how can they be used? 1 Answer
how does invokerepeating work 2 Answers