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

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...