Invoke / Star Coroutine using text from CSV

Hello,

I’m using a csv file to store all the names of my methods. I have two scripts. The first one the my csv “controller” and the second one is where is where I use Invoke to call a specific string from my csv.

CSV Controller Script:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class TextAssetController : MonoBehaviour
{
    //--------------------------------------------------------------

    public static TextAssetController instance { get; set; }
    public TextAsset splashTextAssetsString;

   //--------------------------------------------------------------

    private void Awake()
    {
        instance = this;
    }

    //--------------------------------------------------------------

    public string SplashReadStringLine(int lineNumber)
    {
        string[] assetStringLine = splashTextAssetsString.text.Split('

');
string value = assetStringLine[lineNumber];
return value;
}

    //--------------------------------------------------------------
}

Invoke Splash Script:

using UnityEngine;

public class Splash : MonoBehaviour
{
	//--------------------------------------------------------------

	void Start()
	{
		Blockout.instance.FadeOut ();
		Invoke (TextAssetController.instance.SplashReadStringLine(0),1.0f);
    }

	//--------------------------------------------------------------

	private void FadeSplash()
	{
		Audio.audioInstance.PlayMusic ();
		foreach(Animation animation in MainController.instance.splashAnimation)
		{
			animation.Play (TextAssetController.instance.SplashReadStringLine(3));
		}
	}

	//--------------------------------------------------------------
}

CSV File Content:

  • FadeSplash

The problem: Let say I want to Invoke using TextAssetController.instance.SplashReadStringLine(0) as the method name which is a string I get a message in the console saying: “Trying to Invoke method: Splash.FadeSplash couldn’t be called”.

If I do a Debug.Log(TextAssetController.instance.SplashReadStringLine(0)) then it is debugging the string “FadeSplash” from the CSV file in the console.

Any suggestions?

The problem is in SplashScript line 10.

Invoke (TextAssetController.instance.SplashReadStringLine(0),1.0f);

You cannot pass a Delegate to Invoke’s first argument. You need to pass a string something like this.

Invoke ("TextAssetController.instance.SplashReadStringLine",1.0f);

But this way you wont be able to pass a argument to your function as you want to pass (0). For its workaround you can check this post.

I have the following:

StartCoroutine(TextAssetController.instance.SplashReadStringLine(0));

private IEnumerator FadeSplash()
{
	yield return new WaitForSeconds(1.0f);
	Debug.Log("Splash Faded");
}

When the StartCoroutine is called I get an error saying:

Coroutine ‘FadeSplash’ couldn’t be started!