- Home /
Question by
FoulEntertainment · May 17, 2015 at 07:52 PM ·
datetimeidle
Idle increment game, offline gains issue
I have been trying to get offline gains working on my incremental game. I have the code written, but my skills aren't good enough to see why it isn't working. It's not throwing up any errors, it just doesn't work. Any help would be gratefully appreciated.
public class VirginFriends : MonoBehaviour {
private DateTime oldDate;
private DateTime currentDate;
private int saved = 0;
private int saved2 = 0;
private double totsec;
public WasteTime wastetime;
public ClickHaveNoFriends hnf;
public int numberOfVirgins = 0;
public int cost = 1000;
void Start ()
{
saved = PlayerPrefs.GetInt ("savedVF");
saved2 = PlayerPrefs.GetInt ("SavedClick");
if (saved > 0) {
if(saved2 > 0){
numberOfVirgins = PlayerPrefs.GetInt("SavedVir");
cost = PlayerPrefs.GetInt("SavedCostVir");
}
long temp = Convert.ToInt64(PlayerPrefs.GetString("time"));
currentDate = System.DateTime.Now;
oldDate = DateTime.FromBinary(temp);
TimeSpan difference = currentDate.Subtract(oldDate);
totsec = difference.TotalSeconds;
wastetime.seconds += (float)(totsec * hnf.power * numberOfVirgins);
}
}
void Update()
{
saved = 1;
PlayerPrefs.SetInt ("savedVF", saved);
PlayerPrefs.SetString ("time", System.DateTime.Now.ToBinary ().ToString ());
}
public void Clicked()
{
if (wastetime.seconds >= cost) {
numberOfVirgins += 1;
wastetime.seconds -= cost;
cost = cost * 2;
saved2 = 1;
PlayerPrefs.SetInt ("SavedVir", numberOfVirgins);
PlayerPrefs.SetInt ("SavedCostVir", cost);
PlayerPrefs.SetInt("SavedClick", saved2);
}
}
}
wastetime is where my currency (seconds) is stored. hnf is what I want use to increment wastetime with.
Comment
Your answer
Follow this Question
Related Questions
How to write If the player don't play the game for 24 hours, the game is over. 1 Answer
C# DateTime inspector 2 Answers
Date field for UI inputfield? 0 Answers
How to save DateTime in a list 1 Answer
Playing a second idle animation... 1 Answer