Need help using the the system clock for timekeeping

I have a simple Mars rover game where you control a rover by sending commands like “forward 10 meters, turn 30 degrees, deploy experiment 1”. I want there to be a delay i was wondering how i could pre-simulate what happens then if the player quits i could use the system clock of my computer so that if the program is opened again it would know how long it has been?

p.s. excuse my spelling i’m from finland

p.p.s. MSL4LIFE

You can use PlayerPrefs to store the quit time in OnApplicationQuit. Then have a script that, when the application is first started, calculates the time difference.

A one-time script like that can be achieved by e.g. an empty scene apart from a gameobject with the time calculating script, that is loaded as the first scene. After the time has been calculated it loads the actual main menu scene.

As for your simulation, it seems more like a forum question. I’ll tell you what I’d do: I would use an AI system based on ticks. A tick could be, for instance 0.1 seconds. After you’ve figured out the time difference, you could calculate how many ticks have passed and do the corresponding amount of AI calculation.

Here is a bit of code that saves and restores the time to using PlayerPrefs:

using UnityEngine;
using System.Collections;

public class Bug20 : MonoBehaviour {
	void Update() {
		if (Input.GetKeyDown (KeyCode.S)) {
			SaveTime ();
			Debug.Log ("Time saved.");
		if (Input.GetKeyDown (KeyCode.E)) {
			int seconds = ElapsedTime ();
			Debug.Log (seconds.ToString ()+" seconds since the last time save");
	void SaveTime() {
		long ticks = System.DateTime.Now.Ticks;
		PlayerPrefs.SetString ("Time", ticks.ToString ());
	int ElapsedTime() {
		string st = PlayerPrefs.GetString("Time", null);
		if (st == null) return 0;
		long l;
		if (!long.TryParse (st, out l))
			return 0;
		long deltaTicks = System.DateTime.Now.Ticks - l;
		long milliSeconds = deltaTicks / System.TimeSpan.TicksPerMillisecond;
		return (int)(milliSeconds / 1000L);