Jump to content

How do I add a wait command to my module


Recommended Posts

Hello. This is probably a silly question, but I can't figure out how to make the game wait before doing the action I have coded it to do (load the last quicksave). I currently have this code segment:

public override void OnActive()

{

UnityEngine.Debug.Log("[FK] Time Traveling");

Game _game = GamePersistence.LoadGame("quicksave", HighLogic.SaveFolder, true, true);

//Wait 3 Seconds here

_game.Start();

}

If someone could please help me out here and possible direct me to a good source to look off of that would be great. :) Thanks

Link to comment
Share on other sites


public void OnActive()
{
StartCoroutine(CoroutineExample());
}

public System.Collections.Generic.IEnumerable CoroutineExample()
{
yield return new WaitForSeconds(3);
game.Start();
}

Look up unity coroutines for more info

Link to comment
Share on other sites


public void OnActive()
{
StartCoroutine(CoroutineExample());
}

public System.Collections.Generic.IEnumerable CoroutineExample()
{
yield return new WaitForSeconds(3);
game.Start();
}

Look up unity coroutines for more info

OK, I tried this and got a Null Reference

using System;

using System.Collections;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using UnityEngine;

//Unnecessary Code Stuffs Removed for Convenience

public override void OnActive()

{

Debug.Log("[FK] Time Traveling");

StartCoroutine(WaitThree());

}

IEnumerator WaitThree()

{

yield return new WaitForSeconds(3);

Game _game = GamePersistence.LoadGame("quicksave", HighLogic.SaveFolder, true, true);

_game.Start();

}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...