Beispiel #1
0
    private bool ExplodeTile(int xTile, int zTile)
    {
        Vector3 ExpolsionCenterWorldSpace = owner.Arena.transform.TransformPoint(new Vector3(xTile, 0, zTile));

        Collider[] hits   = Physics.OverlapBox(ExpolsionCenterWorldSpace, Vector3.one / 3f, Quaternion.identity, BombsHitLayer);
        Collider[] blocks = Physics.OverlapBox(ExpolsionCenterWorldSpace, Vector3.one / 3f, Quaternion.identity, BombsBlockedLayer);

        //Is blocked
        if (blocks.Length > 0)
        {
            return(true);
        }

        //Do come visual gargabe
        if (ShowDeBugExplosion)
        {
            Debug.DrawLine(ExpolsionCenterWorldSpace + new Vector3(0.5f, 0, 0.5f), ExpolsionCenterWorldSpace + new Vector3(-0.5f, 0, -0.5f), Color.red, 0.2f);
            Debug.DrawLine(ExpolsionCenterWorldSpace + new Vector3(0.5f, 0, -0.5f), ExpolsionCenterWorldSpace + new Vector3(-0.5f, 0, 0.5f), Color.red, 0.2f);
        }
        else
        {
            Instantiate(ExplosionGrapic, ExpolsionCenterWorldSpace, Quaternion.identity, null);
        }

        //Call hits on players and bomb in square!
        for (int i = 0; i < hits.Length; i++)
        {
            //Skip if object is not in right cell
            bool sameX = Mathf.RoundToInt(hits[i].gameObject.transform.localPosition.x) == xTile;
            bool sameZ = Mathf.RoundToInt(hits[i].gameObject.transform.localPosition.z) == zTile;
            if (!sameX || !sameZ)
            {
                continue;
            }

            PlayerController player = hits[i].GetComponentInParent <PlayerController>();
            if (player != null)
            {
                player.Hit(owner);
            }

            BombController bomb = hits[i].GetComponentInParent <BombController>();
            if (bomb != null)
            {
                bomb.Hit(owner);
            }

            BoxController box = hits[i].GetComponentInParent <BoxController>();
            if (box != null)
            {
                box.Hit(owner);
                return(true);
            }
        }

        return(false);
    }