void Start() { finalWinAnimation = GameObject.Find("FinalWinAnimation"); finalWinAnimation.SetActive(false); finalLostAnimation = GameObject.Find("FinalLostAnimation"); finalLostAnimation.SetActive(false); if (PlayerPrefs.GetInt("Lvl").Equals(0)) { PlayerPrefs.SetInt("Lvl", 1); } myGameDifficulty = (float)PlayerPrefs.GetInt("Lvl"); timeDivider = 10f - (0.8f * myGameDifficulty); if (timeDivider < 5f) { timeDivider = 5f; } var introTextGo = GameObject.Find("IntroText").GetComponent <Text>(); var introTextGoTitle = GameObject.Find("Title").GetComponent <Text>(); if (PlayerPrefs.GetInt("Lvl").Equals(1)) { introTextGoTitle.text = "MATCH"; } else { introTextGoTitle.text = "MATCH FASTER"; } var introTextGoSubTitle = GameObject.Find("Subtitle").GetComponent <Text>(); introTextGoSubTitle.text = "To trade"; iTween.MoveTo(introTextGo.gameObject, iTween.Hash( "x", -145f, "time", 0.6f, "oncomplete", "OnCompleteShowInstructions", "oncompletetarget", gameObject, "oncompleteparams", introTextGo.gameObject, "easetype", iTween.EaseType.easeInBounce, "islocal", true )); float rowSum = 0.45f, columnSum = -1.35f; for (int i = 0; i < MATRIX_ROWS; i++) { for (int j = 0; j < MATRIX_COLUMNS; j++) { var objInfo = new MatrixPositionInfo { positionx = columnSum, positiony = rowSum, isUsed = false }; matrix[i, j] = objInfo; columnSum += 0.45f; } rowSum -= 0.45f; columnSum = -1.35f; } drawObstacles(); drawObstacles(); mySlider = this.gameObject.GetComponentInChildren <UnityEngine.UI.Slider>(); }
public void createAnObstacle(MatrixPositionInfo objInfo, int i, int j) { var objectNum = 0; var positionRandom = UnityEngine.Random.Range(0f, 600f); var wichOne = UnityEngine.Random.Range(0f, 600f); if (myGameDifficulty % 15 == 0 || myGameDifficulty % 10 == 0) { objectNum = 0; } else { objectNum = positionRandom < 150 ? 0 : positionRandom >= 150f && positionRandom < 300f ? 1 : positionRandom >= 300f && positionRandom < 450f ? 2 : positionRandom >= 450f && positionRandom < 600f ? 3 : UnityEngine.Random.Range(0, 3); } switch (objectNum) { case 0: //generateCrosses generateCrosses(objInfo.positionx, objInfo.positiony); matrix[i, j].isUsed = true; break; case 1: //generateHorizontalObstacles bool isOneUsed = false; float directionRandom = UnityEngine.Random.Range(0f, 600f); var direction = positionRandom < 150 ? true : positionRandom >= 150f && positionRandom < 300f ? false : positionRandom >= 300f && positionRandom < 450f ? true : positionRandom >= 450f && positionRandom < 600f ? false : true; for (int col = 0; col < MATRIX_COLUMNS; col++) //search for at least one used { if (matrix[i, col].isUsed) { isOneUsed = true; } } if (!isOneUsed) { for (int col = 0; col < MATRIX_COLUMNS; col++) // Set all row to used { matrix[i, col].isUsed = true; } generateHorizontalObstacles(objInfo.positiony, direction); } break; case 2: //pinch var howManyFails = 0; bool waPositioned = false; if (j - 1 >= 0) { if (!matrix[i, j - 1].isUsed) { generatePinch(objInfo.positionx - 0.225f, objInfo.positiony); matrix[i, j].isUsed = true; matrix[i, j - 1].isUsed = true; waPositioned = true; } else { howManyFails++; } } else { howManyFails++; } if (j + 1 < MATRIX_COLUMNS) { if (!matrix[i, j + 1].isUsed) { if (!waPositioned) { generatePinch(objInfo.positionx + 0.225f, objInfo.positiony); matrix[i, j].isUsed = true; matrix[i, j + 1].isUsed = true; } } else { howManyFails++; } } else { howManyFails++; } break; case 3: //generateLinesBackAndForward bool isOneColUsed = false; for (int col = 0; col < MATRIX_COLUMNS; col++) //search for at least one used { if (matrix[i, col].isUsed) { isOneColUsed = true; } } if (!isOneColUsed) { for (int col = 0; col < MATRIX_COLUMNS; col++) // Set all row to used { matrix[i, col].isUsed = true; } generateLinesBackAndForward(-0.6f, objInfo.positiony, true); matrix[i, j].isUsed = true; } break; } }