Fade to black on player death.
Objective: Create short cutscene when player dies.
Create a new game object named Cutscene to hold the various fade to black effects. Create another empty game object named Oubliette. Add a timeline from Unity window > sequencing menu, saving in the Timelines folder.
Add a UI Canvas to Oubliette, allowing it to scale with screen size with a 1920x1080 resolution.
To the Canvas add a UI Image, Fade_To_Black_img, adjusting the color to be black (0, 0, 0, 0). Set the anchor points to be stretch-stretch for the rect transform and zero its position. The animator will be added later through Unity timeline.
Next add a UI text object, and set up as shown below. Adjusting the color, the text message and the font size and positioning. The animator will be added later through Unity timeline.
The hierarchy should appear as below.
Install Cinemachine from the package manager if not installed. Select Oubliette object and open the timeline window. Add the main camera to the timeline, which should have the CinemachineBrain, to add a cinemachine track. Next add animation tracks for Fade_To_Black_img and Text. For each record the color alpha to be zero at 0 seconds and 255 at three seconds. Select Oubliette when finished and inactivate it by unchecking the box next to its name. The cutscene should start inactive.
On the Player script create four new variables using SerializeField to assign them in the inspector, shown below. One of these will hold Oubliette cutscene reference.
Add an OnEnterTrigger2D to the Player script as shown below. There are two types of Oubliettes in game, the Oubliette2 is shallower, thus can be escaped if the player has Boots Of Flight. If the Player is triggered by an Oubliette, the Oubliette cutscene is activated, and the player is returned to the main menu after 5 seconds using the ReturnToMainMenu coroutine.
The Oubliettes are empty game objects with a box collider 2D with is trigger checked. The box colliders are adjusted for each Oubliette, as shown, and tagged Oubliette for 1 , 2 & 4, as these cannot be escaped. Oubliettes 3 & 5 are tagged Oubliette2 as if the player has boots of flight escape is possible.
Cutscenes for player death due to monsters or falling or escaping the dungeon can be created with a similar approach.