How to OnDeath call Function

I want Load Scene or later other actions to be done after Death of player. Using OnplayButton becouse it works in other script of Unity Event

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class EndGamePlayerDeath : MonoBehaviour
{
    // Called when we click the "Play" button.
    public void OnPlayButton()
    {
        SceneManager.LoadScene(1);
    }

    
}

I suggest you start with any of the ten billion Youtube tutorials already out there for this.

If you are unable to figure it out from those, I guarantee you won’t figure it out from this little tiny text box!

Two steps to tutorials and / or example code:

  1. do them perfectly, to the letter (zero typos, including punctuation and capitalization)
  2. stop and understand each step to understand what is going on.

If you go past anything that you don’t understand, then you’re just mimicking what you saw without actually learning, essentially wasting your own time. It’s only two steps. Don’t skip either step.

Imphenzia: How Did I Learn To Make Games:

No. You think you are logical straight to point but you are not and 99% of those Tutorials. Based is 2+2=4. 99% Of those tutorials are 2+2= Philosophy open 1000x other programs write 10000X other code Think Philosophy Critical errors. Give me link where si tutorial and it says

Unity event - 1. Press unity event 2. Create scripts 3. Attach script(To what?) 4. Write in scripts this 5. All games are different and 70% tutorials are about some strange shizo indie gamez. Cant it be just 3d shooter like Doom for example? Most standart game type

You think you are based but you are not. Based = straight to the point simple not 1000000 philosophy and critical errors

Tutorials should be used to learn the basics of Unity, or certain aspects of Unity. Beyond that point you should really be able to proceed under your own initiative. If you have to regularly follow step-by-step instructions to get anything done in Unity, then you have not been learning.

Game dev is about learning concepts and applying them in practice. You do not make a game by following instructions every step of the way.

Kurt’s generic response is down to your questions being very hard to understand. I also don’t really have an idea as to what you’re asking.

The forums aren’t here to write code for you to but to help you with specific issues. You haven’t really outlined what the issue is here. You need to describe your problem, and what you have tried, and why it doesn’t work.

You’ve been asking these sorts as questions as far back as 2022. It’s in your best interest to buckle down and do some solid learning. Try starting here: Junior Programmer Pathway - Unity Learn

Ok. Give me link to Official Unity Manual where it says How use On death event. 1. Press on death 2. Create Scripts 3. Attach script to what? 4. What wright in script 5. What choose in event?
This is based and short and logical not 10000000 philosophy with critical errors more questions more difficulties etc.

That’s not the purpose of the Unity manual, sorry. It teaches you how to use the engine in broad strokes. You have a specific, high-level problem made up of many smaller pieces.

There are plenty of resources on how to use Unity Events in general. Then you should be able to apply that knowledge to your specific case. There’s a section in the manual on Unity events, too: Unity - Manual: UnityEvents

If you are not willing to learn these concepts then you will not have much luck in game dev.

What is your specific issue here? Is it getting something to happen when the player dies? Is it actually getting that ‘death’ event working? Is it an issue with setting up UI? You are not providing enough details.

There is no “On Death” event until you make it.

There is not even any death until you make it, and some games don’t even have death!

Generally death works like this:

  • the game gathers your input and moves your character
  • when certain conditions are detected, you can’t do that anymore.

This is commonly referred to as “death”

So figure out what “death” means in your game, where that condition is decided (again, tutorials are invaluable for examples here), and do what you need to do when that happens.

Don’t overthink it. Gamedev is made of lots of very very very very simple parts.

1 Like