Alternate Fade Transitions Code

Here is my code for the fade transition.

I Used:
Image.CrossFadeAlpha (0, fadeInDelay, true);
Starting with a black background and the alpha set to 255, the command fades the alpha channel to the first variable passed over the time fadeInDelay and true to Ignore realtime.

I then check if the timeSinceLevelLoaded is greater then the fadeInDelay and deactivate the panel.

Enjoy,
John Cordeiro

5 Likes

I did the exact same thing before watching the video solution. Got totally confused by the long way they did it.
Is there some reason as to why this solution wouldn’t be recommended for a fadeIn/FadeOut?

2 Likes

I did the same way. Just added “SetActive” function after watching a video but I used Invoke to call it, because for some reason it didn’t fade in all the way through before panel was disabled. Here is my code:

public float fadeTime = 5f;

void Start () {
	GetComponent<Image>().CrossFadeAlpha(0f, fadeTime, false);
	Invoke ("SetAsInactive", fadeTime);
}

void SetAsInactive(){
	gameObject.SetActive(false);
}
3 Likes

Privacy & Terms