Example #1
0
    public void Gravitate()
    {
        colliders = Physics2D.OverlapCircleAll(this.transform.position, 100);

        foreach (Collider2D hit in colliders)
        {
            switch (PlayerShot)
            {
            case true:
                if (hit.gameObject.name == "EnemyBullet")
                {
                    thisBullet = hit.GetComponent <BulletDirection>();
                    if (holeDestroyed)
                    {
                        thisBullet.DestroyWithHole();
                    }
                    thisBullet.lighningOnce = true; // prevent Electric Charge hit
                    applyForce(thisBullet.gameObject);
                }

                if (hit.gameObject.name == "EnemyMissile")
                {
                    thisMissile = hit.GetComponent <Missile>();
                    thisMissile.lighningOnce = true;
                    if (holeDestroyed)
                    {
                        thisMissile.DestroyWithHole();
                    }
                    applyForce(thisMissile.gameObject);
                }
                break;

            case false:
                if (hit.gameObject.name == "PlayerBullet")
                {
                    thisBullet = hit.GetComponent <BulletDirection>();
                    if (holeDestroyed)
                    {
                        thisBullet.DestroyWithHole();
                    }
                    thisBullet.lighningOnce = true;
                    applyForce(thisBullet.gameObject);
                }

                if (hit.gameObject.name == "PlayerMissile")
                {
                    thisMissile = hit.GetComponent <Missile>();
                    thisMissile.lighningOnce = true;
                    if (holeDestroyed)
                    {
                        thisMissile.DestroyWithHole();
                    }
                    applyForce(thisMissile.gameObject);
                }
                break;
            }
        }
    }