Created
April 25, 2023 14:50
-
-
Save TheCuttlefish/780a115c516d38236d6306ade8b960ab to your computer and use it in GitHub Desktop.
Screen Fade
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Fade : MonoBehaviour | |
{ | |
CanvasGroup group; | |
float timer; | |
float fadeOutTimer; | |
bool startFadeOut; | |
[Range(1f,5f)] | |
public float seconds = 1f; | |
void Awake() | |
{ | |
group = GetComponent<CanvasGroup>(); | |
group.alpha = 1f; | |
} | |
void Update() | |
{ | |
if (timer < 1) | |
{ | |
timer += Time.deltaTime / seconds ; | |
group.alpha = 1 - timer; | |
}else | |
{ | |
group.alpha = 0f; | |
} | |
if (Input.GetKeyDown(KeyCode.Space)) | |
{ | |
startFadeOut = true; | |
} | |
if (startFadeOut) | |
{ | |
if (fadeOutTimer < 1) | |
{ | |
fadeOutTimer += Time.deltaTime / seconds ; | |
group.alpha = fadeOutTimer; | |
}else | |
{ | |
group.alpha = 1f; | |
print("load scene!!"); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment