Exemplo n.º 1
0
 private void Start()
 {
     if (explosive == null)
     {
         explosive = GetComponent <IExplosive>();
     }
     if (explosive == null)
     {
         explosive = GetComponentInParent <IExplosive>();
     }
 }
Exemplo n.º 2
0
    private IExplosive FindTarget()
    {
        int x        = 0;
        int y        = 0;
        var rotation = transform.rotation;

        if (rotation.y == 0 && rotation.z == 0)
        {
            x = 1;
            y = 0;
        }
        else if (rotation.y < 0 && rotation.z == 0)
        {
            x = -1;
            y = 0;
        }
        else if (rotation.y == 0 && rotation.z <= 0)
        {
            x = 0;
            y = -1;
        }
        else
        {
            x = 0;
            y = 1;
        }

        var     pointX = transform.position.x + x * 0.85f;
        var     pointY = transform.position.y + y * 0.85f;
        Vector2 bomb   = new Vector2(transform.position.x, transform.position.y);
        Vector2 area   = new Vector2(pointX, pointY);

        Collider2D[] coliders = Physics2D.OverlapAreaAll(bomb, area);
        foreach (var colider in coliders)
        {
            IExplosive explosive = colider.gameObject.GetComponent <IExplosive>();
            if (explosive != null)
            {
                return(explosive);
            }
        }

        return(null);
    }
Exemplo n.º 3
0
 // Start is called before the first frame update
 void Start()
 {
     explosive = GetComponent <IExplosive>();
 }
Exemplo n.º 4
0
    private void Kaboom()
    {
        IExplosive target = FindTarget();

        target.explode();
    }