#I have Issue with CrossFadeAlpha.

1 messages · Page 1 of 1 (latest)

cosmic marlin
#

Use CrossFadeAlpha when game finish and timeScale to 0 and IEnumerator call when my created Action is accurse.
Everything work perfect and I debug code it works perfectly, but Fade In/Out not working.
Anyone have solution for this problem?

Code :-
IEnumerator StartAnimation()
{
CheckPointImage.enabled = true;
CheckPointImage.canvasRenderer.SetAlpha(0.0f);
CheckPointImage.CrossFadeAlpha(1.0f, 1.0f, false);

        yield return new WaitForSeconds(3f);
    }
static quiver
# cosmic marlin Use CrossFadeAlpha when game finish and timeScale to 0 and IEnumerator call whe...

I don't have a solution but some ideas:
do you call the alpha methods on the right objects?
does CrossFadeAlpha work in general? if you try it on some object without any of the other methods?
Coroutines are stopped and dropped when a gameObject it is called on becomes inactive, maybe it's the same for CrossFadeAlpha that the alpha state is being managed somewhere and that is lost. but if that is the case not sure how to fix it

if everything doesn#t work, you can fade alpha manually

float duration = 1f;
float startAlpha = 0f;
float endAlpha = 1f;
float timer = 0f;
while (timer < duration) {
    timer += Time.deltaTime; 
    float alpha = Mathf.Lerp(startAlpha, endAlpha, timer / duration);
    obj.SetAlpha(alpha);
    yield return null; //  Pause and continue next frame
}
obj.SetAlpha(endAlpha);

and replace obj.SetAlpha with the method and object you need

flint spade
#

Also, is using a coroutine really necessary? It waits for 3 seconds at the end and then does nothing. Unless you're going to expand it I don't really see a reason for it.

static quiver
#

oh yeah I missed that,
if you use a coroutine here, you'd want to use Time.unscaledDeltaTime for my example
and if you do WaitForSeconds, you'd do WaitForSecondsRealtime instead
but your WaitForSeconds(3f);
really does nothing, it just keeps the coroutine around longer for that reason. keep in mind that this doesn't prevent you from spawning multiple coroutines of that type. if you want to prevent this you have to manage it manually.

CrossFadeAlpha might use scaled time, if so that's the reason why it wouldn't work then
when you do UI stuff, you'd usually always want to use unscaled time/realtime

cosmic marlin