Exemplo n.º 1
0
    void DoDamage(float damage, int layer, IDamage self)
    {
        //get hits this frame
        RaycastHit[] hits = GetHits(layer);

        //foreach hit
        foreach (RaycastHit hit in hits)
        {
            //only if hit something
            if (hit.transform == null)
            {
                continue;
            }

            IDamage enemyHit = hit.transform.GetComponentInParent <IDamage>();

            //if can hit
            if (CanHit(enemyHit, self))
            {
                //add to already hits
                alreadyHits.Add(enemyHit);

                //and do damage
                enemyHit.ApplyDamage(self, damage);
            }
        }
    }