예제 #1
0
    // Called once per frame, after all physics & collision checks
    void Update()
    {
        // If the bullet has collided with anything, then damage one.
        // If it only hits something invulnerable, then hit it. Otherwise damage something else
        bool         damagedSomething = false;
        Invulnerable invulnToHit      = null;

        while (objsToHit.Count > 0)
        {
            GameObject nextObj = objsToHit [0];
            if (nextObj == null)
            {
                objsToHit.RemoveAt(0);
                continue;
            }

            Invulnerable I = nextObj.GetComponent <Invulnerable> ();
            if (I != null && I.enabled)
            {
                invulnToHit = I;
                objsToHit.Remove(nextObj);
            }
            else if (dealDamage(nextObj, _damage, transform.position, objT.typ, transform.right))
            {
                //(GetComponent<seeking_missile>() && GetComponent<ObjT>() && GetComponent<ObjT>().typ == ObjT.obj.enemy_bullet)
                if (ricochetsLeft > 0)
                {
                    ricochet(nextObj);
                    lastHit = nextObj;
                }
                else
                {
                    die();
                }

                objsToHit.Clear();
                damagedSomething = true;
            }
            else
            {
                objsToHit.Remove(nextObj);
            }
        }

        if (!damagedSomething && invulnToHit != null)
        {
            invulnToHit.gotHit();
            die();
        }
    }