I want to make a script for my 2D game that can detect when a player collides with a certain object (a projectile in my case) and then transports him to a death screen that has the same options as the main menu (play, quit etc) but it has the player’s score that was achieved during the game. I’ve already written a script for counting the score and it’s as follows:
public class Score : MonoBehaviour
{
float playerScore = 0;
public Text scoreText;
void Update() {
playerScore += Time.deltaTime*15;
scoreText.text = playerScore.ToString("0");
}
}
From what I can tell you want to make a death screen, correct? Well, you should have some graphics ready, the simplest solution is just having a black UI sprite (Name it whatever you want but i suggest Death Screen). Make an animation for said black UI Sprite (Just call it “FadeInAnimation”) Use keyframes to lerp its opacity from 0-1. Then, in the Death Screen’s animator, just make sure the fade in animation is connected to the Entry node. In your player script, make a reference to the death screen like this : public GameObject deathScreen; make a function that is called when the player dies. In that function write: deathScreen.SetActive(true); and in the Start() function write deathScreen.SetActive(false); Then, when you want to restart the game, just play the Fade in animation backwards.