|
Hi there, I am having issues with the following code. I want it to flash between 2 different textures... it works well for a few seconds and then starts swapping between the textures erratically. I have a similer process in another part of my game, almost identical code and it works perfectly. I have tried and tried to get this going but it's just not working. I have tried with bools, for loops (to flash a predetermined amount of times) and nothing has worked. Is there anything obvious that I have missed? Any help gladly appreciated!!!
(comments are locked)
|
|
I belive it's time to make it an answer. It's completely normal that Unity doesn't like an empty while(true), because the processor get stuck until it hit a yield (in that case). You should do that instead : And when you change bTextIsNotFlashing to true, affect the correct texture as well. Thanks, only just saw this. Accepted and up-voted :)
Feb 13 '12 at 05:07 AM
POLYGAMe
Oh, by the way, it was originally bTextIsFlashing... but I got deeper and deeper into crap and ended up changing it for some reason... can't remember why but it's back to what it was originally though anyway. I remember thinking that the Unity Answers guys would think that was an odd name for a bool! LOL.
Feb 13 '12 at 05:08 AM
POLYGAMe
(comments are locked)
|

It's the bit in the WHILE TRUE loop that is giving me trouble, the damage gauge works well.
Oh, before I forget, I also had the exact same issue when I tried this with a GUIText, rather than a GUITexture object...
If you're calling that in Update, it's making new instances of the coroutine every frame, which would account for the erratic behavior.
Ah, I thought it might be something like that... but how do I call it without being called from Update? It needs to be checking constantly throughout gameplay... and the other text I have is being called from Update and that works... so weird...
Create a function (FlashTex or something) with a while( true ). Put your flashing code inside an if scope, with a boolean (let's say bFlash). Start your coroutine on awake, then toggle bFlash if you need the texture to flash or not. I hope I'm making sense !