Start coroutine with his name in param

Hello,

I’d like to launch a coroutine from my main program with his name store in a variable.

In my main, i have something like that :

MethodInfo methodInfoFunction = myTouchGO.GetType ().GetMethod (_cardFunction, BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Instance, null, new[]{ typeof(MethodInfo), typeof(float)}, null);

myTouchGO.GenericStartMethod (methodInfoFunction, duration);

In my myTouchGo script, i have :

public void GenericStartMethod(MethodInfo functionName, float _duration){
	StartCoroutine (functionName.Name, _duration);
}

In my main program, i check the collision and associated element used to collide, this element provide the name of the coroutine.

I’d like a clean code without a lot of “switch case” this is the reason i want to take the coroutine name method in my concerned elements.

Thanks for your help :slight_smile:

More information :

  • methodInfoFunction is null on a run.
  • myTouchGo is connected to the coroutine function script.
  • the string_cardFunction contains the name of the existing coroutine

Hi,

I find a solution, i put my GetMethod into the element script, it works and more simple :

public void GenericStartMethod(string functionName, float _duration){
	System.Type myType = this.GetType ();
	MethodInfo myMethodInfo = myType.GetMethod (functionName, BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance);
	StartCoroutine (myMethodInfo.Name, _duration);
}

In my main, i call :

myTouchGO.GenericStartMethod (_cardFunction, duration);