UI won't update during (stalling the rest of the method) an Elapsed timed event.
So I was playing around with timing for my main project, and all my updates had been in the debug console. But I went over to a "playground project," doing some other testing. And I notice: This method will not allow me to update text inside the timed event. And it stalls the rest of the method. I want to avoid using Coroutines in my normal project because they are not good for my combat system I am working on.
However to simplify the help I will be using my playground project to shorten it:
public void activate()
{
if (active == false)
{
Debug.Log("Start Timers");
active = true;
StartTick();
}
}
private void GetSomeCash(object source, ElapsedEventArgs e)
{
Debug.Log("Get some Cash");
gameController.money += 500;
Debug.Log(gameController.money);
gameController.UpdateMoney();
Debug.Log("Update Money");
active = false;
Debug.Log("Set active to false");
tickRate.Stop();
Debug.Log("Finish GetSomeCash");
}
private void StartTick()
{
Debug.Log("Started Tick");
tickRate = new Timer(defaultSeconds * 1000);
tickRate.Elapsed += GetSomeCash;
tickRate.AutoReset = false;
tickRate.Enabled = true;
}
Then the method UpdateMoney()
inside the game controller is simple:
public void UpdateMoney()
{
moneyText.text = money.ToString();
}
Now I do know the actual update works outside of the timing.
It stalls when I call the update method, and I don't really know why. (Yes I am aware I can just do a Coroutine, but I'd like to not do that.)
Your answer
Follow this Question
Related Questions
How to reset timer smoothly? 0 Answers
c# How would I go about doing a High Score Board? 1 Answer
Race saving best times on different scene 0 Answers
How to stop a countdown timer and disable/stop everything in the scene? 1 Answer
Timer Countdown Pop Up Screen Before Scene "Starts" Please Help!! 2 Answers