Player death event

General support.
Post Reply
User avatar
pyatyorochka
Contributor
Contributor
Posts: 31
Joined: Sun Jun 13, 2021 4:55 am

Hello! What event do I need to trigger to kill the player?
For example: I have a mine. When the mine is touched, an explosion occurs and the player must die. How can I make the player die? ;)
User avatar
Lovatto
Admin
Admin
Posts: 1834
Joined: Sun Dec 07, 2014 3:18 pm
Contact:

Hi,

If you want to deal damage to the local player you can call the function DoDamage(...) of bl_PlayerHealthManager.cs which expects a DamageData with the information about the damage, e.g:

Code: Select all

void DealDamageFunction()
    {
        if(Physics.Raycast(transform.position, transform.forward, out RaycastHit raycast, 10))
        {
            if (raycast.collider.isLocalPlayerCollider())
            {
                var playerReferences = raycast.transform.GetComponent<bl_PlayerReferences>();
 
                DamageData damageData = new DamageData()
                {
                    Damage = 20, // base damage to apply
                    Direction = transform.position,
                    Cause = DamageCause.Player,
                    MFPSActor = bl_MFPS.LocalPlayer.MFPSActor, // MFPS actor that cause this damage
                    // Check the other DamageData properties
                };
 
                playerReferences.playerHealthManager.DoDamage(damageData);
            }
        }
    }
I hope this helps,
Regards.
How to find your Invoice Number: Here
How to find your Order Number: Here
Post Reply