So, I have a feature in my project which checks if the player’s Coin count is < 50 then starts a 10-second timer.
Once the timer hits 0, It gives the player another coin and resets the timer to 10.
This continues until 50 again.
The below script I have works, so long as the Coin count starts below 50 (because it’s being called on start).
I’m derping and can’t figure out how to have it called once the player’s coin count (save.coincount) goes from 50 to 49.
The only way I can figure out to check is in update, but it obviously starts the timer multiple times and bugs out.
public int time = 10;
public SaveScript save;
public bool TimerActive = false;
void Start()
{
StartTimer();
}
public void StartTimer()
{
if(save.coinCount < 50)
{
TimerActive = true;
time = 10;
InvokeRepeating ("UpdateTimer", 1.0f, 1.0f);
}
else
{
return;
}
}
void FixedUpdate()
{
NextCoinTextTMP.text = ("Next coin in: " + time.ToString());
if (time == 0 && save.coinCount < 50)
{
save.coinCount++;
time = 10;
}
if(save.coinCount > 49)
{
textObject.SetActive(false);
TimerActive = false;
time = 10;
}
else
{
textObject.SetActive(true);
}
}
void UpdateTimer()
{
time--;
}
If anyone can help, I would greatly appreciate it.