Example #1
0
    void OnTriggerEnter(Collider collider)
    {
        if (collider.gameObject.tag.Equals("Block"))
        {
            body.velocity = new Vector3(body.velocity.x * -1, body.velocity.y, body.velocity.z);

            if (collider.gameObject.GetComponent <BasicBlock>() is BasicBlock)
            {
                BasicBlock block = collider.gameObject.GetComponent <BasicBlock>();
                block.DecreaseToughness();

                if (block.getIsBreakable() && block.getToughness() == 0)
                {
                    PaddleController script = owner.GetComponent <PaddleController>();
                    script.IncreaseScore(block.getPoint());
                    Destroy(collider.gameObject);
                }
            }

            if (collider.gameObject.GetComponent <ToughBlock>() is ToughBlock)
            {
                ToughBlock block = collider.gameObject.GetComponent <ToughBlock>();
                block.DecreaseToughness();

                if (block.getIsBreakable() && block.getToughness() == 0)
                {
                    PaddleController script = owner.GetComponent <PaddleController>();
                    script.IncreaseScore(block.getPoint());
                    Destroy(collider.gameObject);
                }
            }
        }
    }
    //---------------------------------------------------------------------------------------------------------------------
    //---------------------------------------------------------------------------------------------------------------------

    #region 3) BUILD BLOCKS
    void SetLevelBlocks(List <GroundTileScript> gtList, GameObject _blockPrefab, GameObject parentTransform)
    {
        // Sets the blocks based on the hasBlockOnIt bool for each tile in groundCells.
        Vector3 yOffset = new Vector3(0, 2.1f, 0);  // based on the tile prefab's half height. Jerry-rigged here for the time being.

        foreach (GroundTileScript gt in gtList)
        {
            Vector3 spawnPos = gt.transform.position + yOffset;
            if (gt.tileReference.hasBlockOnIt)
            {
                GameObject       dataBlock   = GameObject.Instantiate(_blockPrefab, spawnPos, Quaternion.identity, parentTransform.transform);
                LevelBlockScript dBComponent = dataBlock.AddComponent <LevelBlockScript>();


                switch (gt.tileReference.type)
                {
                case GroundTile.GroundType.CLEAR:
                    BasicBlock basicMinableDB = new BasicBlock(gt, true);
                    dBComponent.levelBlockReference = basicMinableDB;
                    dBComponent.levelBlockReference.dBlockRenderer = dataBlock.gameObject.GetComponent <MeshRenderer>();
                    dBComponent.levelBlockReference.dBSpriterndr   = dataBlock.gameObject.GetComponentInChildren <SpriteRenderer>();
                    dBComponent.levelBlockReference.dBHoverandSel  = dataBlock.gameObject.GetComponentInChildren <HoverAndSelection>();
                    dBComponent.levelBlockReference.dBHoverandSel.isInterractable = true;
                    dataBlock.AddComponent <Mineable>();
                    dataBlock.AddComponent <Explodable>();
                    break;

                case GroundTile.GroundType.ROUGH:
                    ToughBlock toughMinableDB = new ToughBlock(gt, true);
                    dBComponent.levelBlockReference = toughMinableDB;
                    dBComponent.levelBlockReference.dBlockRenderer = dataBlock.gameObject.GetComponent <MeshRenderer>();
                    dBComponent.levelBlockReference.dBSpriterndr   = dataBlock.gameObject.GetComponentInChildren <SpriteRenderer>();
                    dBComponent.levelBlockReference.dBHoverandSel  = dataBlock.gameObject.GetComponentInChildren <HoverAndSelection>();
                    dBComponent.levelBlockReference.dBHoverandSel.isInterractable = true;
                    dataBlock.AddComponent <Mineable>();
                    dataBlock.AddComponent <Explodable>();
                    dataBlock.AddComponent <Tough>();
                    break;

                case GroundTile.GroundType.IMPASSABLE:
                    UnbreakableBlock unbreakableDB = new UnbreakableBlock(gt, false);
                    dBComponent.levelBlockReference = unbreakableDB;
                    dBComponent.levelBlockReference.dBlockRenderer = dataBlock.gameObject.GetComponent <MeshRenderer>();
                    dBComponent.levelBlockReference.dBSpriterndr   = dataBlock.gameObject.GetComponentInChildren <SpriteRenderer>();
                    dBComponent.levelBlockReference.dBHoverandSel  = dataBlock.gameObject.GetComponentInChildren <HoverAndSelection>();
                    dBComponent.levelBlockReference.dBHoverandSel.isInterractable = false;
                    break;

                case GroundTile.GroundType.HAZARD:
                    CorruptBlock corruptMinableDB = new CorruptBlock(gt, true);
                    dBComponent.levelBlockReference = corruptMinableDB;
                    dBComponent.levelBlockReference.dBlockRenderer = dataBlock.gameObject.GetComponent <MeshRenderer>();
                    dBComponent.levelBlockReference.dBSpriterndr   = dataBlock.gameObject.GetComponentInChildren <SpriteRenderer>();
                    dBComponent.levelBlockReference.dBHoverandSel  = dataBlock.gameObject.GetComponentInChildren <HoverAndSelection>();
                    dBComponent.levelBlockReference.dBHoverandSel.isInterractable = true;
                    dataBlock.AddComponent <Mineable>();
                    dataBlock.AddComponent <CleanMeImCorrupted>();
                    break;

                default:
                    BasicBlock defaultBasicBlock = new BasicBlock(gt, true);
                    dBComponent.levelBlockReference = defaultBasicBlock;
                    dBComponent.levelBlockReference.dBlockRenderer = dataBlock.gameObject.GetComponent <MeshRenderer>();
                    dBComponent.levelBlockReference.dBSpriterndr   = dataBlock.gameObject.GetComponentInChildren <SpriteRenderer>();
                    dBComponent.levelBlockReference.dBHoverandSel  = dataBlock.gameObject.GetComponentInChildren <HoverAndSelection>();
                    dBComponent.levelBlockReference.dBHoverandSel.isInterractable = true;
                    dataBlock.AddComponent <Mineable>();
                    dataBlock.AddComponent <Explodable>();
                    Debug.Log("No usable info found, using default block state");
                    break;
                }
                dBComponent.levelBlockReference.LoadPropertiesDB();

                dBComponent.levelBlockReference.dBHoverandSel.isInterractable = dBComponent.levelBlockReference.isBreakable;
                dBComponent.levelBlockReference.dBHoverandSel.hsSprite        = dBComponent.levelBlockReference.dBSpriterndr.sprite;
                dBComponent.levelBlockReference.dBHoverandSel.SetSpriteRef();

                dataBlock.name = "Block ID: " + dBComponent.levelBlockReference.dBlockID + " | Coords z/x: " + dBComponent.levelBlockReference.dBlock_YorZ + " ; " + dBComponent.levelBlockReference.dBlock_X;
            }
            else
            {
                continue;
            }
        }
    }