Hi,
I am trying to make my invoke repeating work, depending on the value of the variable TimeSelector, but it only activates on game start and then doesn’t repeat.
EDIT: So I have now updated the code, so that the InvokeRepeating value is changed when the buttons are changed, but now InvokeRepeatingVAR gets stuck set to 15, and won’t change.
The code is:
using UnityEngine;
using System.Collections;
using System;
using UnityEngine.UI;
using System.Collections.Generic;
public class MainGameScript : MonoBehaviour {
DateTime GameTime;
public Text DateDisplayer;
public Text Month;
public Text Year;
public Boolean MediumTimeIsSelected;
public Boolean FastTimeIsSelected;
public GameObject MediumTimeArrow1;
public int UpdateDateCounter;
public int MonthNumber;
public int YearNumber;
public int counter;
public string TimeSelector;
public int InvokeRepeatingVar;
public int CancelInvokeDecider;
void UpdateDate()
{
GameTime = GameTime.AddDays(7);
counter++;
Debug.Log("workingTime");
}
// Use this for initialization
void Start () {
GameTime = System.DateTime.Now;
}
//Update is called once per frame
void Update()
{
if (counter == 4)
{
MonthNumber++;
counter = 0;
}
if (MonthNumber == 12)
{
MonthNumber = 1;
YearNumber++;
MonthNumber = 0;
}
DateDisplayer.text = GameTime.ToString("dd-MM-yyyy");
Month.text = MonthNumber.ToString();
Year.text = YearNumber.ToString();
TimeSelector = PlayerPrefs.GetString("TimeSelector");
if (TimeSelector == "FastTime")
{
InvokeRepeatingVar = 15;
if (!IsInvoking("UpdateDate"))
{
InvokeRepeating("UpdateDate", InvokeRepeatingVar, InvokeRepeatingVar);
}
}
//==---------------------------------------------
if (TimeSelector == "MediumTime")
{
InvokeRepeatingVar = 30;
if (!IsInvoking("UpdateDate"))
{
InvokeRepeating("UpdateDate", InvokeRepeatingVar, InvokeRepeatingVar);
}
}
//------------------------------------
if (TimeSelector == "NormalTime")
{
InvokeRepeatingVar = 60;
if (!IsInvoking("UpdateDate"))
{
InvokeRepeating("UpdateDate", InvokeRepeatingVar, InvokeRepeatingVar);
}
}
Debug.Log(InvokeRepeatingVar);
Debug.Log(TimeSelector);
CancelInvokeDecider = PlayerPrefs.GetInt("CancelInvoke");
if (CancelInvokeDecider == 1)
{
CancelInvoke("UpdateDate");
CancelInvokeDecider = 0;
}
}
private void invoke(string v)
{
throw new NotImplementedException();
}
}