IEnumerator ContinueGameCoruoutine() { alreadyContinued = true; //Get the difference in x and z scale of the current block and desired block. float xScale = continueBlockSize - currentBlock.transform.lossyScale.x; float zScale = continueBlockSize - currentBlock.transform.lossyScale.z; //Will instantiate these many blocks to get to the desired size int steps = 3; for (int i = 0; i < steps; i++) { if (i < steps - 1) { SoundManager.Instance.playSound(AudioClips.split); } else { SoundManager.Instance.playSound(AudioClips.perfect); } yield return(new WaitForSeconds(0.1f)); GameObject block = objectPooler.GetPooledObject(ObjectPoolItems.Block, true); block.transform.SetParent(stack); block.GetComponent <BlockScript>().enabled = false; //Assign the scale and position block.transform.localScale = baseBlock.transform.localScale + new Vector3(xScale / steps, 0, zScale / steps); block.transform.localPosition = baseBlock.transform.localPosition + Vector3.up * yOffset; //Align the position of the new block according to the last split Vector3 posDiff = new Vector3(baseBlock.localPosition.x + baseBlock.lossyScale.x / 2, 0, baseBlock.localPosition.z + baseBlock.lossyScale.z / 2) - new Vector3(block.transform.localPosition.x + block.transform.lossyScale.x / 2, 0, block.transform.localPosition.z + block.transform.lossyScale.z / 2); block.transform.localPosition -= posDiff; //Create a new material for the block and set its color and texture blockMat = new Material(Shader.Find(shaderType)); blockMat.SetColor("_Color", colorController.BlockColor); blockMat.mainTexture = selectedSkinTexture; block.GetComponent <MeshRenderer>().material = blockMat; MeshUVAdjuster.AdjustUVs(block.transform); //Update Camera pos and set this block and baseblock cameraController.UpdatePos(); baseBlock = block.transform; } //continue game isGameRunning = true; Invoke("ActivateInputWithDelay", 0.2f); BringNewBlock(); }
/// <summary> /// This is when the game has initialised but has not started. /// </summary> void InitGame() { objectPooler.disableAllPooled(); baseBlock = startBaseBlock; //Reset the Color conttoller and assign the first colors colorController.Reset(); baseBlock.GetComponent <MeshRenderer>().material.SetColor("_Color", colorController.BlockColor); MeshUVAdjuster.AdjustUVs(baseBlock); //So that we start with default speed for the first block blockSpeed = defaultBlockSpeed - blockSpeedDelta; #if ARENABLED if (isARModeOn) { blockCount = 0; } #endif #if ADSENABLED alreadyContinued = false; #endif }