Hello,
so I am trying to automate my system a little bit, basically I am trying to make it so I declare everything that I want to happen line after line, and then my code saves all this into a List and runs them one after the other. Now that’s good and all, but I have a small problem, when I want the game to just wait a certain amount of time (because I want cinematics to play while this wait function plays or something else).
So I am using coroutines of course, and after running my wait function, nothing happens, it doesn’t run the next line, so please help?
Thanks!
here is my code:
public bool isDone = true;
List<string> methodList = new List<string>();
void Start ()
{
AddNext("test", new string[] { "hey" });
AddNext("wait", new string[] { "10" });
AddNext("test", new string[] {"hey"});
}
void AddNext (string method, string[] args)
{
string temp = method + "_" + string.Join("_", args); ;
methodList.Add(temp);
StartCoroutine(AddNextNow());
}
IEnumerator AddNextNow()
{
string methodNow = methodList[0];
if (isDone)
{
isDone = false;
string[] all = methodList[0].Split('_');
if (all[0] == "test")
{
Test(all[1]);
}
else if (all[0] == "wait")
{
yield return StartCoroutine_Auto(Wait(float.Parse(all[1])));
}
methodList.Remove(methodList[0]);
isDone = true;
if (methodList[0] != null) {
StartCoroutine(AddNextNow());
}
}
}
void Test (string input)
{
Debug.Log("Test! " + input);
}
IEnumerator Wait (float delay)
{
Debug.Log("Waiting...");
yield return new WaitForSeconds(delay);
Debug.Log(methodList[0]);
}