Untitled

 avatar
unknown
plain_text
3 years ago
1.0 kB
3
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExplosiveBrick : BrickBase
{
    public int explosionRange = 1;
    public LayerMask brickLayer;
    int explosiveBrickDamage = 999;
    public Collider2D[] bricksInRadius;

    public override void Awake()
    {
        base.Awake();
        GetBricksToExplode();
    }

    public override void Dead()
    {
        Explode();
        gameManager.BrickHasDied();
        Destroy(this.gameObject);
    }

    void Explode()
    {
        foreach (Collider2D brick in bricksInRadius)
        {
            BrickBase bb = brick.gameObject.GetComponent<BrickBase>();
            bb.Damage(explosiveBrickDamage);
        }

    }

    void GetBricksToExplode()
    {
        bricksInRadius = Physics2D.OverlapBoxAll(transform.position, new Vector2(explosionRange, explosionRange), 0f, brickLayer);
    }

    private void OnDrawGizmos()
    {
        Gizmos.DrawWireCube(transform.position, new Vector3(explosionRange, explosionRange, 0f));
    }
}
Editor is loading...