Thanks! :D Good to be back too.Hi Minamu, good to have you back! :) And good luck with these guys!
And I'm back with another Unity question! :D I've been following a video tutorial, linked at the bottom, on how to make UI elements fade in and out. It works as intended but I've noticed a bug I can't seem to correct.
Basically, each time I press a UI button, a menu panel will fade in, and if there's already an active panel, that one must fade out as the new panel fades in. That part is fine.
The problem is that if you press an additional button while the previous panel is still fading in, via a coroutine, things break, and the coroutines get messed up. I suppose Unity doesn't like it when you force quit a coroutine before it's done? The video below fade panels (or rather the whole Canvas) via a CanvasGroup and its alpha value, and I've tried to continuously capture the alpha value in a float, so I can reset the value, but it doesn't want to stick :/ My non-working solution would be to save the alpha value, and when I force quit a coroutine, I will start a new one with the new alpha value, so it fades out again down to zero from that cancelled alpha value so to speak, but alas, it doesn't work :/ I think the coroutines get stuck inside the while loops, and doesn't reach 0 properly. The value isn't supposed to be able to go below 0 or above 1, but for some reason, sometimes it gets stuck at for example 1.2392124214^e-5 and keeps rambling on xD
This should be easy imo xD I want to tell the code to simply cancel any ongoing fade ins, and convert their alpha value when the cancel was ordered to the new starting point so 0 is reached faster than normal.
Fake edit: After giving it some thought, I think I need to save what I call the currentPanel in an extra temporary variable, and maybe also for the newPanel (that needs to fade in). I'm not sure what happens when you cancel a coroutine though, or if I can even catch that. Right now we're saving the started coroutine in a temporary coroutine so we can check if it's != null, and then do some stuff, but does that variable become null as soon as the coroutine has stopped? Essentially, I need to swap some panels around I think, because once inside the function that calls these coroutines, currentPanel and newPanel are known, and newPanel becomes currentPanel at the end. If I were to call this function again whil still running, I'd have two panels in the same variable, so no wonder it breaks xD
Explaining all this at almost 6am is difficult, heh. Sorry if I'm not making any sense!
TLDR: I can fade UI panels in and out no problem, as long as I don't touch them. But if I try to start a new fade before the previous ones are done, it breaks.
https://www.youtube.com/watch?v=MkoIZTFUego