Esempio n. 1
0
 private void DoExplode()                                                           //Explodes the bomb
 {
     Collider2D[] hitColliders = Physics2D.OverlapCircleAll(transform.position, 1); //Gets a list of all colliders within a certain range of our game object
     for (int i = 0; i < hitColliders.Length; i++)                                  //loop through this list
     {
         //We want colliders which are attackable or destroyable
         AttackableBase attackable  = hitColliders[i].gameObject.GetComponent <AttackableBase>();
         Destroyable    destroyable = hitColliders[i].gameObject.GetComponent <Destroyable>();
         //If any, do thing
         if (destroyable != null)
         {
             Destroy(destroyable.gameObject);                      //Destroy it
         }
         if (attackable != null)
         {
             attackable.OnHit(hitColliders[i], ItemType.Bomb);                     //Attack it
         }
     }
     if (ExplosionEffect != null)                                               //If no explosion effect
     {
         GameObject explosionEffect = (GameObject)Instantiate(ExplosionEffect); //Do explosion
         explosionEffect.transform.position = transform.position;               //At center of bomb
     }
     Destroy(gameObject);                                                       //Destroy bomb
 }
Esempio n. 2
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        AttackableBase attackable = collision.gameObject.GetComponent <AttackableBase>();

        if (attackable != null)
        {
            attackable.OnHit(m_Collider);
        }
    }
Esempio n. 3
0
    private void OnTriggerEnter2D(Collider2D ObjectCollision)
    {
        Debug.Log(ObjectCollision.name);
        AttackableBase Attackable = ObjectCollision.GetComponent <AttackableBase>();

        if (Attackable != null)
        {
            Attackable.OnHit(type);
        }
    }
Esempio n. 4
0
    void OnCollisionEnter2D(Collision2D collision)
    {
        Debug.Log("Hit " + collision.gameObject.name);
        AttackableBase attackable = collision.gameObject.GetComponent <AttackableBase>();

        if (attackable != null)
        {
            attackable.OnHit(Type);
        }
    }
Esempio n. 5
0
 private void OnTriggerEnter2D(Collider2D col)
 {
     if (isThrown)
     {
         AttackableBase attackable = col.GetComponent <AttackableBase>();
         if (attackable != null)
         {
             attackable.OnHit(m_Collider);
         }
     }
 }
    protected void OnTriggerEnter2D(Collider2D collider)
    //If the collisionbox isnt a trigger, use OnCollisionEnter2D(Collision2D collision)
    //If the collisionbox is a trigger, us OnTriggerEnter2D(Collider2D collider)
    {
        //Debug.Log("hit " + collider.gameObject.name);
        AttackableBase attackable = collider.gameObject.GetComponent <AttackableBase>();

        //collision.gameObject.GetComponent gets the component of the gameobject this gameobject collides with somehow
        //Here it get attackablebase, that would also return attackablebush. In fact, it will return all derivatives
        //Debug.Log(collider.name, collider.gameObject);
        if (attackable != null)
        {
            attackable.OnHit(m_Collider, Type, 2);
            //So if the attackable doesnt return null, the OnHit function of the AttackableBase will run
            //It will only return null if the other gameobject has no attackablebase or derivative thereof
        }
    }