private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Bullet"))                                     //if collider tag is bullet
        {
            BulletScript script = other.GetComponent <BulletScript>();      //get the script refrence
            if (script.DestroyPlayer == false)                              //if destroy player is false
            {
                damageScript.ReduceHealth(script.DamageAmount);             //do damage
            }
            other.gameObject.SetActive(false);                              //set the collided object deactive
        }

        if (other.CompareTag("Player"))                                     //if its player object
        {
            other.GetComponent <DamageScript>().ReduceHealth(damAmount);    //do damage to it
        }
    }
Exemple #2
0
    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Bullet"))                                     //if colliding gameobject is bullet
        {
            BulletScript script = other.GetComponent <BulletScript>();      //get the script component
            if (script.DestroyPlayer == false)                              //check if its to destroy player is false
            {
                damageScript.ReduceHealth(script.DamageAmount);             //do damage
            }
            other.gameObject.SetActive(false);                              //deactivate gameobject
        }

        if (other.CompareTag("Player"))                                     //if the gamobject is player
        {
            other.GetComponent <DamageScript>().ReduceHealth(damAmount);    //do damage
        }
    }