Exemplo n.º 1
0
    void OnTriggerEnter2D(Collider2D collision) //checks for collision, this section works EXACTLY the same as a regular bullet
    {
        if (collision.gameObject.tag == "Enemy")
        {
            if (collision.gameObject.name == "SkeletonPrefab(Clone)")
            {
                SkeletonScript skeletonScript = collision.gameObject.GetComponent <SkeletonScript>();
                skeletonScript.health = skeletonScript.health - bulletDamage;
            }

            if (collision.gameObject.name == "VampirePrefab(Clone)")
            {
                VampireScript vampireScript = collision.gameObject.GetComponent <VampireScript>();
                vampireScript.health = vampireScript.health - bulletDamage;
            }

            if (collision.gameObject.name == "WitchPrefab(Clone)")
            {
                WitchScript witchScript = collision.gameObject.GetComponent <WitchScript>();
                witchScript.health = witchScript.health - bulletDamage;
            }
        }
    }
Exemplo n.º 2
0
 void OnTriggerEnter2D(Collider2D collision)                                                       //detect collision
 {
     if (collision.gameObject.tag == "Enemy")                                                      //check to see if what we are colliding with is an enemy
     {
         if (collision.gameObject.name == "SkeletonPrefab(Clone)")                                 //if it's a Skeleton
         {
             SkeletonScript skeletonScript = collision.gameObject.GetComponent <SkeletonScript>(); //get the Skeleton's script
             skeletonScript.health = skeletonScript.health - bulletDamage;                         //subtract the bullet's damage from the Skeleton's health
             Destroy(gameObject);                                                                  //destroy the bullet
         }
         else if (collision.gameObject.name == "VampirePrefab(Clone)")                             //if it's a Vampire
         {
             VampireScript vampireScript = collision.gameObject.GetComponent <VampireScript>();    //get the Vampire's script
             vampireScript.health = vampireScript.health - bulletDamage;                           //subtract the bullet's damage from the Vampire's health
             Destroy(gameObject);                                                                  //destroy the bullet
         }
         else if (collision.gameObject.name == "WitchPrefab(Clone)")                               //if it's a Witch
         {
             WitchScript witchScript = collision.gameObject.GetComponent <WitchScript>();          //get the Witch's script
             witchScript.health = witchScript.health - bulletDamage;                               //subtract the bullet's damage from the Witch's health
             Destroy(gameObject);                                                                  //destroy the bullet
         }
     }
 }