A
A
Alexander Ilchuk2021-04-20 23:20:25
Unity
Alexander Ilchuk, 2021-04-20 23:20:25

Hello. Could you help how to make a death counter in Unity 2D?

When a player falls off a platform or dies from an enemy, this counter would be displayed in the corner of the screen. help me please

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
nik_pron, 2021-04-21
@nik_pron

1. Create a text field: Create - UI - Text
2. Create a script - DeathCounter
3. Call methods when you die or start a new game
// I myself recently started learning and do this, so if this is wrong, I will be glad if you help me to become on true path =)

using UnityEngine;
using UnityEngine.UI;

public class DeathCounter : MonoBehaviour
{
    private static int deathCount = 0;
    [SerializeField] private Text textUIDeathCount;
    public static DeathCounter deathCounter;

    private void Start() {
        deathCounter = this;
    }
    public static void drawText() {
        deathCounter.textUIDeathCount.text = "Смертей:  " + deathCount;
    }

    public static void resetDeathCount() {
        deathCount = 0;
        drawText();
    }

    public static void upDeath() {
        deathCount++;
        drawText();
    }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question