how to get a death screen

hi i am creating a simple touch game in that game i used my player to die using OnCollisionEnter2d as soon as after the player dies i need my death screen to appear(i have a death screen created) so how can i do that(i am new to unity & scripting)

If your death screen is simply a different scene…

Then make sure that your death scene is part of your build index.

To add it to your build index:

  • Open your death scene
  • Click on “File” on the top left of Unity
  • Click on “Build Settings”
  • Click on the “Add Open Scenes” button

Once that’s done, add this to your player script:

    using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    using UnityEngine.SceneManagement;
    
    public class PlayerScript: MonoBehaviour
    {
        private void OnCollisionEnter2D(Collision2D collision)
        {
            // Put your scene name where "SceneName" is.
            SceneManager.LoadScene("SceneName");
        }
    }

Don’t forget to include “using UnityEngine.SceneManagement;” on the top

GameObject DeathScreen; //in inspector, put here your panel (UI) with death ‘screen’

void OnCollisionEnter2d ()
{
DeathScreen.SetActive(true);
}