예제 #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        int realDmg             = DealtDamage;
        PotionEffectsScript pes = gameObject?.transform?.parent?.gameObject?.GetComponent <PotionEffectsScript>();

        if (pes != null)
        {
            realDmg = (int)(realDmg * pes.Strength);
        }

        Collider2D[] colliders = Physics2D.OverlapBoxAll(new Vector2(gameObject.transform.position.x + collider.offset.x, gameObject.transform.position.y + collider.offset.y), new Vector2(collider.bounds.size.x * 2, collider.bounds.size.y * 2), 0, AffectedLayer);
        for (int i = 0; i < colliders.Length; i++)
        {
            if ((AffectedLayer.value & (1 << colliders[i].gameObject.layer)) > 0)
            {
                HealthPointsScript hps = (colliders[i].GetComponent(typeof(HealthPointsScript)) as HealthPointsScript);
                if (hps != null)
                {
                    hps.GetHit(realDmg);
                }
                if (SelfDestroy)
                {
                    this.gameObject.SetActive(false);
                }
            }
        }
    }
예제 #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        Collider2D[] colliders = Physics2D.OverlapBoxAll(new Vector2(gameObject.transform.position.x + collider.offset.x, gameObject.transform.position.y + collider.offset.y), new Vector2(collider.bounds.size.x / 2, collider.bounds.size.y / 2), int.MaxValue);
        for (int i = 0; i < colliders.Length; i++)
        {
            GameObject        collider = colliders[i].gameObject;
            AbstractAfectable af       = (AbstractAfectable)colliders[i].GetComponent(typeof(AbstractAfectable));

            if (af != null)
            {
                af.OnExplode();
            }

            HealthPointsScript hps = (colliders[i].GetComponent(typeof(HealthPointsScript)) as HealthPointsScript);
            if (hps != null)
            {
                hps.GetHit(150);
            }
        }
    }