TakeDamage.OnCollisionEnter C# (CSharp) Method

OnCollisionEnter() public method

public OnCollisionEnter ( Collision collider ) : void
collider Collision
return void
    void OnCollisionEnter(Collision collider)
    {
        // if character is not immune to enemy damage, he will detect these
        if (!immuneToEnemyDamage)
        {
            // Touching enemy hurts you
            if (collider.transform.tag == "Enemy")
            {
                theCharacterHealth.removeHealth(1f);
                theCharacterHealth.Invincibility();
            }
        }

        // if character is not immune to player damage, he will detect these
        if (!immuneToPlayerDamage)
        {
            {
                // Touching player hurts you
                if (collider.gameObject.tag == "Player" && ChestUPG.SpikeArmor == true)
                {
                    theCharacterHealth.removeHealth(1f);
                    theCharacterHealth.Invincibility();
                }
            }
        }

        // if character is not immune to hazard damage, he will detect these
        if (!immuneToHazardDamage)
        {
            if (collider.gameObject.tag == "Spikes")
            {
                theCharacterHealth.removeHealth (1f);
                theCharacterHealth.Invincibility ();
            }

            if (collider.gameObject.tag == "Lava")
            {
                theCharacterHealth.removeHealth (2f);
                theCharacterHealth.Invincibility ();
                HazardKnockback = new Vector3 (0,LavaKnockback,0);
                GetComponent<Rigidbody>().velocity = transform.TransformDirection(HazardKnockback);
            }

            if (collider.gameObject.tag == "Masher")
            {
                theCharacterHealth.removeHealth (999f);
                theCharacterHealth.Invincibility();
            }
        }
    }