
I dont know much about this problem, in fact, Im assuming this is GLSL, and Ive never written any GLSL in my life, so if there is anything crappy going on, its most likely centered around me.
I think there is at least one problem, that Im not too sure about. What do we expect to happen if isCloacked changes from true to false, then 2 seconds later back to true. Do we expect to have two timers running, one switching one way, the other back?
Generally, I think I would try to have the current % mix (as a float) stored outside of the logic, and have an event triggered at each time event. At the point that the function is triggered we move the % one way if we are cloaked, and the other if we are not. That way we dont worry about counters and stuff (we just need to know how long it is since the last event, so we can scale the changes). This should allow us to have a change in our cloakedness mid change without breaking anything.
If we do it this way, then we simply do not make any changes if the mix is 1.00 and going up, or 0.00 and going down.
A potential problem with this strategy, is that we might have a seriously large number of events firing for every tick of the clock (one for each texture you do this with, per ship in the whole system), but I think it should be possible to do something to sort that out.
Im not sure if that helpful or not, it makes sense to me, but not really knowing the language, I wonder if Im doing more harm than good.