Esempio n. 1
0
        //method which keep spawning block when the player solves one
        public void SpawnBlock()
        {
            //get the block
            GameObject block = ObjectPooling.instance.GetSpawnedBlock();
            //assign the position in the world
            block.transform.position = new Vector3(transform.position.x, transform.position.y + 3f, transform.position.z);
            //assign the rotation
            block.transform.rotation = Quaternion.identity;
            BlockScript blockScript = block.GetComponent<BlockScript>();//get reference to the script on the block
            //check if list of pieces has any element
            if (blockScript.pieces.Count > 0)
            {
                //if yes goes through all the pieces and apply settings
                for (int i = 0; i < blockScript.pieces.Count; i++)
                {//call the reset methode which resets the position and rotation of block as default
                    blockScript.pieces[i].ResetPosition();

#if UNITY_5_4_OR_NEWER
                    blockScript.pieces[i].isRayOn = false;
#endif
                    blockScript.pieces[i].isKinematic = true;//deactivates it physics effects

                    //give random color from the color range we have 
                    blockScript.pieces[i].pieceSprite.color = newColors[Random.Range(0,newColors.Length)];
                    blockScript.pieces[i].gameObject.SetActive(true); //activate the piece
                }
            }
            //then activate the block
            block.SetActive(true);
        }
Esempio n. 2
0
        //method which spawn stating items
        void StartSpawn()
        {
            Vector2 playerPos = spawnPos.position + new Vector3(0, 0.78f, 0);
            //spawns that hexa 
            GameObject player = (GameObject)Instantiate(hexaPlayer, playerPos, Quaternion.identity);
            playerObj = player;
            player.transform.parent = itemHolder;
            //spawns blocks at the remaining position
            for (int i = 0; i < blocks.Length + 1; i++)
            {
                Vector2 blockPos = spawnPos.position;
                if (i < blocks.Length)
                {
                    //get the block from object pooler
                    GameObject blockObj = (GameObject)Instantiate(blocks[i], blockPos, Quaternion.identity);
                    blockObj.transform.parent = itemHolder;
                    BlockScript blockScript = blockObj.GetComponent<BlockScript>();//get the script attached on the block

                    //we go through each pieces and change there color properties
                    for (int m = 0; m < blockScript.pieces.Count; m++)
                    {
                        //set the color for pieces
                        blockScript.pieces[m].pieceSprite.color = newColors[Random.Range(0, newColors.Length)];
                    }
                    spawnPos.position = blockPos - new Vector2(0, 3.1f);
                }
                else
                {
                    //when all the blocks are spawn at the end we spawn the base
                    GameObject baseObj = (GameObject)Instantiate(basePrefab, blockPos, Quaternion.identity);
                    baseObj.transform.parent = itemHolder;
                    endY = baseObj.transform.position.y;
                }
            }
        }
Esempio n. 3
0
        //method which spawn stating items
        void StartSpawn()
        {
            //gets which hexa skin is selected
            int selectedHexa = GameManager.instance.selectedSkin;
            //spawns that hexa 
            GameObject player = (GameObject)Instantiate(hexaPlayer[selectedHexa], spawnPos[0].position, Quaternion.identity);
            //spawns blocks at the remaining position
            for (int i = 1; i < spawnPos.Length; i++)
            {
                //get the block from object pooler
                GameObject blockObj = (GameObject)Instantiate(blocks[Random.Range(0,blocks.Length)], spawnPos[i].position, Quaternion.identity);
                BlockScript blockScript = blockObj.GetComponent<BlockScript>();//get the script attached on the block

                //we go through each pieces and change there color properties
                for (int m = 0; m < blockScript.pieces.Count; m++)
                {
                    //set the color for pieces
                    blockScript.pieces[m].pieceSprite.color = newColors[Random.Range(0, newColors.Length)];
                }

            }
        }