void Update() { if (gameState == GameState.isActivePlay) { if ((!multiTouchActive || Input.touchCount == 1) && !isMathMode) { if (Input.GetMouseButtonDown(0)) { screenRay = Camera.main.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(screenRay, out hit)) { if (hit.transform.tag == "piece") { redGlow = hit.transform.Find("redGlow"); greenGlow = hit.transform.Find("greenGlow"); whiteGlow = hit.transform.Find("whiteGlow"); moveParticle = hit.transform.Find("moveParticle").gameObject; moveParticle.SetActive(true); if (hit.transform.name == currentPiece.name) { isPieceOnHold = true; onHoldPiece = hit.transform; hit.transform.GetComponent <Piece>().isOnHold = true; offset = hit.transform.position - Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); whiteGlow.gameObject.SetActive(true); } else { redGlow.gameObject.SetActive(true); } } else if (canHoldAnyPiece && hit.transform.tag == "piece") { isPieceOnHold = true; onHoldPiece = hit.transform; hit.transform.GetComponent <Piece>().isOnHold = true; offset = hit.transform.position - Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y)); } } } if (Input.GetMouseButton(0)) //Move { if (isPieceOnHold) { if (onHoldPiece != null) { onHoldPiece.position = (Vector2)(Camera.main.ScreenToWorldPoint(Input.mousePosition)) + offset; //Debug.Log("x: " + Camera.main.WorldToScreenPoint(onHoldPiece.position).x + " y: " + Camera.main.WorldToScreenPoint(onHoldPiece.position).y); if (onHoldPiece.name == currentPiece.name) { if (currentPiece.transform.GetComponent <Piece>().isOnTargetPosition()) { if (!greenGlow.gameObject.activeSelf) { greenGlow.gameObject.SetActive(true); } } else { if (greenGlow.gameObject.activeSelf) { greenGlow.gameObject.SetActive(false); } } } } else { if (redGlow != null && redGlow.gameObject.activeSelf) { redGlow.gameObject.SetActive(false); } } } } if (Input.GetMouseButtonUp(0)) { isPieceOnHold = false; if (onHoldPiece != null) { if (onHoldPiece.name != currentPiece.name) { onHoldPiece.GetComponent <Piece>().returnPiece(); } else { if (currentPiece.transform.GetComponent <Piece>().checkTargetPosition()) { if (pieceSlider.enabled) { pieceSlider.removePiece(currentPiece); } currentPieceIndex++; if (currentPieceIndex < activePieces.Count) { currentPiece = activePieces[currentPieceIndex]; if (pieceSlider.enabled) { pieceSlider.currentPiece = activePieces[currentPieceIndex]; } currentPiece.GetComponent <Piece>().shadow.gameObject.SetActive(true); if (pieceSlider.enabled) { pieceSlider.currentPiece = currentPiece; } } else { if (checkFinishStatue()) { if (hasReversePlay && !isInReverseMode) { reverseGamePlay(); } else { finishGame(false, timeSaveLevel, !timeSaveLevel); } } } if (!isInReverseMode) { piecePlaceSound.Play(); } else { pieceRetakeSound.Play(); } } else { pieceReturnSound.Play(); } } onHoldPiece = null; } if (!pieceRotater.enabled && !pieceRescaler.enabled) { if (greenGlow != null && greenGlow.gameObject.activeSelf) { greenGlow.gameObject.SetActive(false); } } else { if (pieceRescaler.enabled) { if (greenGlow != null) { if (greenGlow.parent.GetComponent <Piece>().isOnTrueScale&& !greenGlow.parent.GetComponent <Piece>().isPlaced) { greenGlow.gameObject.SetActive(true); } else { greenGlow.gameObject.SetActive(false); } } } else if (pieceRotater.enabled) { if (greenGlow != null) { if (greenGlow.parent.GetComponent <Piece>().isOnTrueRotation&& !greenGlow.parent.GetComponent <Piece>().isPlaced) { greenGlow.gameObject.SetActive(true); } else { greenGlow.gameObject.SetActive(false); } } } } if (redGlow != null && redGlow.gameObject.activeSelf) { redGlow.gameObject.SetActive(false); } if (whiteGlow != null && whiteGlow.gameObject.activeSelf) { whiteGlow.gameObject.SetActive(false); } if (moveParticle != null && moveParticle.activeSelf) { moveParticle.SetActive(false); } } } if (!isMathMode) { timer += Time.deltaTime; if (timeText.gameObject.activeSelf) { if (!timeBar.gameObject.activeSelf) { timeBar.startTimer(timeToBeat); } timeText.text = ((int)(timeToBeat + 1 - timer)).ToString(); if ((timeToBeat - timer) <= 10.01f && !countdownFlag) { countdownFlag = true; music.volume = music.volume / 2f; countDownSound.Play(); } if ((timeToBeat - timer) <= 0.2f && countDownSound.isPlaying) { countDownSound.Stop(); } if ((timeToBeat - timer) <= 0.01f && !countDownFlag2) { countDownFlag2 = true; countDownFinishSound.Play(); } if ((timeToBeat - timer) <= -0.5f) { finishGame(true, timeSaveLevel, true); } } } } if (isFinishing) { finishTimer += Time.deltaTime; if (finishTimer >= 2.0f) { finishTimer = 0; isFinishing = false; pauseGame(false); } } }
void Update() { if (State == GameStateBoru.FillWater && valve.GetComponent <Valve>().Opened) { leakingSound.Stop(); if (!fillingSound.isPlaying) { fillingSound.Play(); } } else if (State == GameStateBoru.Leaking) { fillingSound.Stop(); if (!leakingSound.isPlaying) { leakingSound.volume = 1; leakingSound.Play(); } } if (LevelTime < 0 && State != GameStateBoru.MainMenu) { endMenu.gameObject.SetActive(true); countdown.Stop(); mouse.SetActive(false); endMenu.transform.GetChild(1).GetComponent <Text>().text = "Süreniz Doldu."; Time.timeScale = 0; State = GameStateBoru.Paused; } if (currentLevel != null) // Playing a level. { if (LevelTime <= 10.01f && !countDownFlag && !allPlaced) { countDownFlag = true; backgroundMusic.volume = 0.2f; countdown.Play(); } if (LevelTime <= 0.2f && countdown.isPlaying) { countdown.Stop(); } if (LevelTime <= 0.01f && !countDownFlag2) { countDownFlag2 = true; countDownFinish.Play(); } if (PlayerPrefs.GetFloat("Level" + Level + "Percentage") < Place * 100 / NumberOfPipes) { if (Place * 100 / NumberOfPipes > 100) { PlayerPrefs.SetFloat("Level" + Level + "Percentage", 100); } else { PlayerPrefs.SetFloat("Level" + Level + "Percentage", Place * 100 / NumberOfPipes); menu.transform.GetChild(Level).GetChild(2).GetComponent <Text>().text = "%" + PlayerPrefs.GetFloat("Level" + Level + "Percentage"); } } if (allPlaced) { if (countdown.isPlaying) { countdown.Stop(); } if (Level == 1 && !tutorialBool) { tutorial.gameObject.SetActive(true); transform.GetChild(1).gameObject.SetActive(true); currentLevel.SetActive(false); game.gameObject.SetActive(false); tutorialAnimation.AnimationName = "level5_valveOpening"; } if (!allFilled && valve.GetComponent <Valve>().Opened) { if (State != GameStateBoru.MainMenu) { backgroundMusic.volume = 0.3f; StartWater(); } } if (levelCompleted) { Destroy(currentLevel); menu.gameObject.SetActive(true); game.transform.GetChild(4).gameObject.SetActive(false); game.transform.GetChild(4).GetComponent <Slider>().value = 0; game.gameObject.SetActive(false); fillingSound.Stop(); if (State != GameStateBoru.MainMenu) { if (PlayerPrefs.GetInt("LevelsPassed") < 10) { levelsPassed++; PlayerPrefs.SetInt("LevelsPassed", levelsPassed); menu.transform.GetChild(levelsPassed + 1).gameObject.SetActive(true); } } backgroundMusic.volume = 0.5f; timeText.text = ""; timeWarnText.text = ""; State = GameStateBoru.MainMenu; } } else { // Update time and check all placed. if (Level % 2 == 0) { timeText.text = Mathf.Ceil(LevelTime).ToString(); timeWarnText.text = " (Süre %10 azaltıldı.)"; if (!timeBar.gameObject.activeSelf) { timeBar.startTimer(Mathf.Ceil(LevelTime)); } } if (!Grid.countdowning) { LevelTime -= Time.deltaTime; timer += Time.deltaTime; } allPlaced = AllPipesPlaced(); } } }