// Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } //Detecting if the player clicked on the left mouse button and also if there is no animation playing if (Input.GetButtonDown("Fire1")) { //The 3 following lines is to get the clicked GameObject and getting the RaycastHit2D that will help us know the clicked object RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.transform != null) { if (hit.transform.gameObject.name == _MenuButton.name) { GetComponent <AudioSource>().PlayOneShot(MenuSound); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); Application.LoadLevel("MainMenu"); } if (hit.transform.gameObject.name == _ReloadButton.name) { GetComponent <AudioSource>().PlayOneShot(MenuSound); Time.timeScale = 1; isPaused = false; HOTween.Play(); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); Application.LoadLevel(Application.loadedLevelName); } if (hit.transform.gameObject.name == _PauseButton.name && !isPaused && !isCountingDown && !isEnded && HOTween.GetTweenersByTarget(_PlayButton.transform, false).Count == 0 && HOTween.GetTweenersByTarget(_MenuButton.transform, false).Count == 0) { GetComponent <AudioSource>().PlayOneShot(MenuSound); StartCoroutine(ShowMenu()); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); } else if ((hit.transform.gameObject.name == _PauseButton.name || hit.transform.gameObject.name == _PlayButton.name) && !isEnded && !isCountingDown && isPaused && HOTween.GetTweenersByTarget(_PlayButton.transform, false).Count == 0 && HOTween.GetTweenersByTarget(_MenuButton.transform, false).Count == 0) { GetComponent <AudioSource>().PlayOneShot(MenuSound); StartCoroutine(HideMenu()); hit.transform.localScale = new Vector3(1f, 1f, 0); } else if ((hit.transform.gameObject.name == _TestScore.name) && !isEnded && !isCountingDown && !isPaused) { GetComponent <AudioSource>().PlayOneShot(MenuSound); _scoreTotal += _scoreIncrement; UpdateLevel(20 * _scoreIncrement); Util.ButtonPressAnimation(hit.transform.gameObject); } else if ((hit.transform.gameObject.name == _TestLevelEnd.name) && !isEnded && !isCountingDown && !isPaused) { isEnded = true; isPaused = true; StartCoroutine(ShowBoardScore()); Util.ButtonPressAnimation(hit.transform.gameObject); //Update the Level UpdateReachedLevel(); } } } if (isPaused) { return; } if (!isPaused) { timing += 0.001f; progress = (float)(timing * _timerCoef); _Time.transform.localScale = new Vector3(Mathf.Clamp01(progress), _Time.transform.localScale.y, 0); } if (Mathf.Clamp01(progress) >= 1) { isEnded = true; isPaused = true; TweenParms parms = new TweenParms().Prop("position", new Vector3(_TimeIsUp.transform.position.x, -0.85f, -6)).Ease(EaseType.EaseOutQuart); HOTween.To(_TimeIsUp.transform, 0.5f, parms).WaitForCompletion(); StartCoroutine(ShowBoardScore()); } //Update the score (GetComponent(typeof(TextMesh)) as TextMesh).text = _scoreTotal.ToString(); if (PlayerPrefs.GetInt("HighScore") < _scoreTotal && !_BestScoreReached) { _BestScoreReached = true; } if (PlayerPrefs.GetInt("HighLevel") < level && !_BestLevelReached) { _BestLevelReached = true; } }
void Update() { if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } //Detecting if the player clicked on the left mouse button and also if there is no animation playing if (Input.GetButtonDown("Fire1")) { //The 3 following lines is to get the clicked GameObject and getting the RaycastHit2D that will help us know the clicked object Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.transform != null) { if (hit.transform.gameObject.name == _MenuButton.name) { audio.PlayOneShot(MenuSound); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); Application.LoadLevel("MainMenu"); } if (hit.transform.gameObject.name == _ReloadButton.name) { audio.PlayOneShot(MenuSound); Time.timeScale = 1; //isPaused = false; //HOTween.Play (); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); Application.LoadLevel(Application.loadedLevelName); } if (hit.transform.gameObject.name == _PauseButton.name && !isPaused && !isEnded && HOTween.GetTweenersByTarget(_PlayButton.transform, false).Count == 0 && HOTween.GetTweenersByTarget(_MenuButton.transform, false).Count == 0) { audio.PlayOneShot(MenuSound); StartCoroutine(ShowMenu()); hit.transform.localScale = new Vector3(1.1f, 1.1f, 0); } else if ((hit.transform.gameObject.name == _PauseButton.name || hit.transform.gameObject.name == _PlayButton.name) && !isEnded && isPaused && HOTween.GetTweenersByTarget(_PlayButton.transform, false).Count == 0 && HOTween.GetTweenersByTarget(_MenuButton.transform, false).Count == 0) { audio.PlayOneShot(MenuSound); StartCoroutine(HideMenu()); hit.transform.localScale = new Vector3(1f, 1f, 0); } } } // If the bird died and our current score is greater than our saved highscore if (showGameOver && curScore > highscore) { // Set the highscore to our current score highscore = curScore; // Now save the score as our new highscore PlayerPrefs.SetInt("Highscore", highscore); } }
// Update is called once per frame void Update() { ArrayList Matches = new ArrayList(); if (isPaused) { return; } var Infos2 = HOTween.GetTweenInfos(); bool gemIsTweening2 = false; if (Infos2 != null) { for (var x = 0; x <= _arrayOfShapes.GetUpperBound(0); x++) { for (var y = 0; y <= _arrayOfShapes.GetUpperBound(1); y++) { if (HOTween.GetTweenersByTarget(_arrayOfShapes[x, y].transform, false).Count > 0) { gemIsTweening2 = true; } } } } //If no animation is playing if (!gemIsTweening2) { Matches.AddRange(FindMatch(_arrayOfShapes)); //If we find a matched tiles if (Matches.Count > 0) {//timing-=0.9f; if (timing < 0) { timing = 0; } //Update the score _scoreTotal += Matches.Count * _scoreIncrement; foreach (GameObject go in Matches) { Debug.Log(go.tag); //Playing the matching sound GetComponent <AudioSource>().PlayOneShot(MatchSound); //Creating and destroying the effect of matching var destroyingParticle = GameObject.Instantiate(_particleEffectWhenMatch as GameObject, new Vector3(go.transform.position.x, go.transform.position.y, -2), transform.rotation) as GameObject; Destroy(destroyingParticle, 1f); //Replace the matching tile with an empty one foreach (Tweener t in HOTween.GetTweenersByTarget(go.transform, true)) { t.Kill(); } //Destroy the ancient matching tiles Destroy(go); } _FirstObject = null; _SecondObject = null; //Moving the tiles down to replace the empty ones DoEmptyDown(ref _arrayOfShapes); } //If no matching tiles are found remake the tiles at their places else if (_FirstObject != null && _SecondObject != null ) { //Animate the tiles DoSwapMotion(_FirstObject.transform, _SecondObject.transform); //Swap the tiles in the array DoSwapTile(_FirstObject, _SecondObject, ref _arrayOfShapes); _FirstObject = null; _SecondObject = null; } } if (!isPaused) { timing += 0.001f; progress = (float)(timing * _timerCoef); _Time.transform.localScale = new Vector3(Mathf.Clamp01(progress), _Time.transform.localScale.y, 0); } if (Mathf.Clamp01(progress) >= 1) { isEnded = true; isPaused = true; } (GetComponent(typeof(TextMesh)) as TextMesh).text = _scoreTotal.ToString(); UpdateLevel(Matches.Count * _scoreIncrement); }