Answers for "unity fall damage c#"

C#
0

unity fall damage c#

using UnityEngine;

public class Collisions : MonoBehaviour
{
    [Tooltip("In Meters")]public float distanceAllowedToFall;

    float jumpHeight;
    float landingHeight;
    float fallDistance;

    private void OnCollisionExit(Collision collision)
    {
        jumpHeight = transform.position.y;
    }

    private void OnCollisionEnter(Collision collision)
    {
        landingHeight = transform.position.y;
        HealthDrain();
    }

    void HealthDrain()
    {
        fallDistance = jumpHeight - landingHeight;

        if (fallDistance > distanceAllowedToFall)
        {
            // Damage Player
        }
    }
}
Posted by: Guest on January-28-2020

C# Answers by Framework

Browse Popular Code Answers by Language