[Unity 2D/3D Tutorial] Quick, Basic Camera Fade In and Fade Out
Hello. Today I have a quick tutorial for you on a very basic camera fader that can be used to fade scenes in and out. You can set any fade colour – let’s say you’re a fan of deep purple. You can also set the fade speed to give you something slow and gradual, or something quick and snappy. Finally, you can set the fade curve to any curve you want to give you any combination of fading in out, for example a slight flickering effect. The script is available on GitHub with a few of my other scripts.
Scripts:
*----*----* My Playlists *----*----*
Unity Journey Of Discovery (Game Dev and Tutorials):
The Main Course (Maths and Science Concepts Explained Visually:
Eco-Pool Natural Swimming Pool (Build and Progress):
4K Treats (Ultra HD content):
Finger Snacks (Shorter, Unclassified Videos):
*----*----*----*----*----*----*----*
The basic idea is that we create a one-pixel texture, give it a color, set its transparency, and then drag it across the entire screen in front of everything else, updating the transparency over time.
You’ll usually want to call the fading from somewhere in your game, but for demonstration purposes I’m calling it when a specific key is pressed. This, as well as the following public variables, can be set in the editor, as we’ll see later. Next, we select the fading speed and color. We create a default fading curve to allow us to customize the fading sequence, and finally set whether we want the scene to start faded out already.
As our private variables we have a float alpha controlling the current transparency, the texture we want to display over the scene, an integer for the direction of the fade, namely 1 for fading in and -1 for fading out, and finally the time progressed through the fade.
In our start method we set alpha according to whether we want to start faded out or not, and then create a 2D texture consisting of a single pixel. We set the color of that pixel to the supplied fade color, with the current alpha as opacity or transparency. We have to apply this change to the texture.
In our update method we initialize the fading out or fading in only if a fade is not currently in progress, and if the specified key was pressed in that frame. If the scene is faded out completely, we cap alpha at 1 and set time and direction so it will start decreasing alpha. If the scene is faded in completely, we floor alpha at 0 and set the time and direction such that it will start increasing alpha.
All that remains is to actually draw the texture, which we only do if it isn’t completely transparent, and then we update our variable values if the direction is not equal to zero, so if we’re currently in a fading phase. We do this in the OnGUI method, which renders and handles graphical user interface events.
We add deltaTime to our time variable, but we scale it with the specified speed and multiply it with direction to let it read from the fade curve in the correct direction. Then we set alpha to the point on the fade curve for the current time value, and we adjust the color of the one-pixel texture by changing the alpha. Again, we need to apply the change to the texture. Finally, we stop the fading whenever the scene is either fully faded in or fully faded out.
This script is then attached to our camera, and we can run our scene with the default input values. Every time we pressed the space bar, the scene fades in our out, depending on its current state. You can now play around with these input values to give you different effects. And there you have it – a very basic camera fader. As I’ve said at the start, the script is available in GitHub, with the link in the description. Go forth and fade!
1 view
65
15
2 months ago 00:08:41 1
Procedural Walking Animation in Minecraft
2 months ago 15:33:59 1
Unity - Лучший курс | С Нуля до Junior за ОДНО видео
2 months ago 00:15:39 3
Большой бесплатный курс Unity с нуля. Установка UnityHub и Unity
2 months ago 00:10:20 1
How to Animate Characters in Unity 3D | Blend Trees Explained: One Dimensional
2 months ago 01:41:15 1
Q&A о Nau Engine: все, что вы хотели спросить, в одном видео
3 months ago 00:26:23 5
Как создать игру с нуля | Все подробности для начинающих
3 months ago 00:22:46 1
Как нарисовать горохострела (Растения VS Zombies) в Blender 3D
3 months ago 00:10:13 1
Как получить любой курс БЕСПЛАТНО
3 months ago 00:32:24 12
MagicaVoxel с нуля. Туториал для новичков by Artalasky
3 months ago 00:07:53 1
Конец 3д художникам?
3 months ago 00:22:12 1
Разработка игр | Языки программирования и Программы
3 months ago 00:21:52 1
СОЗДАНИЕ ШУТЕРА В UNITY. Стрельба Raycast C# | Unity урок by Artalasky
3 months ago 00:06:57 1
ОБЛОЖКА КАК У 3TERNITY | Обложка в DAZ STUDIO 3D | ЧАСТЬ 5
3 months ago 00:11:42 1
Модуль Inventory для Game Creator | Unity
3 months ago 00:28:37 1
BLENDER 3.0 - Rune Stone (Part 2) Creating 3D Model | 3D Modeling | 3D Texturing
3 months ago 00:08:14 1
Quick Sculpting Workflow | Stylised ROCK in Blender 3D
4 months ago 00:11:16 1
СОЗДАНИЕ GAME READY МОДЕЛИ ДЛЯ ИГРЫ В ZBRUSH , 3d coat, Substance Painter, UNITY | Artalasky Gamedev
4 months ago 00:09:49 1
Создание игр Unity 3D | Cтарт программирования на C# | Школа программирования для детей онлайн
4 months ago 00:47:31 1
Как экономят разработчики игр?
4 months ago 00:05:01 59
5 Games Made in Godot To Inspire You
4 months ago 00:06:28 3
2D Top Down игра на Unity с нуля #1 | Вступление
4 months ago 00:12:44 3
ГАЙД - БЫСТРАЯ АНИМАЦИЯ пиксель арт персонажей для инди игр в Photoshop. Как создать игру на Unity
4 months ago 00:07:17 1
Как сделать платформер на Unity #2 | Анимации и слежение камеры