I have been working on a minimalist style game recently, and after seeing some other games with cool transitions between scenes, I decided I would give it a go. I wanted a simple white bar to go across the screen from the center, maybe about 1/6 of the screen height, and then expand up and down to fill the screen. This animation would then reverse itself to reveal the next scene. My basic idea was to use a persistent canvas with an image object in it, and then lerp between values to give the effect of animation. This however decided it did not want to work, and I was wondering what people on here think is the best way to achieve what I mentioned above.
I am open to all suggestions, but preferably in C#.
In theory your basic idea is correct! Have one canvas object set to overlay, and use DontDestroyOnLoad to make it stick around through scene transitions. Give it a script like “TransitionManager” or w/e and give it a couple static variables that you can access from anywhere in your code.
private static TransitionManager reference; //this is a reference
void Awake() {
reference = this; //do this so you can access your local reference (which holds the actual canvas object you move) from static classes
DontDestroyOnLoad(gameObject); //so this doesn't get deleted between scenes
}
public static void ShowOverlay() {
reference.ShowOverlayLocal();
}
public void ShowOverlayLocal() {
//display your overlay here, lerp it onto the screen, whatever
}
public static void HideOverlay() {
reference.HideOverlayLocal();
}
public void HideOverlayLocal() {
//hide overlay here
}
You might run into an issue where you get multiple of these in the same scene, if you go back into the scene where this spawns. In that case, in Awake() just use a tag to check if any of these already exist, and if so, delete the new one (leave the original one alone).
This is p much exactly what I do in my game to achieve the effect you’re describing, so yeah, you were on the right track. Hope this helps!