void Update() { if (tracking) { p = src.time / length; levelText.setPercent((int)(p * 100f)); if (p >= 1f) { // song completed PlayerScript playerScript = GameObject.Find("Player").GetComponent <PlayerScript>(); int idx = GameObject.Find("Control").GetComponent <ConfigLoader>().songIdx; float highScore = PlayerPrefs.GetFloat("HighScore_" + idx.ToString()); if ((playerScript.score + 1f) > highScore) { highScore = playerScript.score + 1f; PlayerPrefs.SetFloat("HighScore_" + idx.ToString(), highScore); } playerScript.gameWin = true; //playerScript.gameObject.SetActive(false); playerScript.renderer.enabled = false; playerScript.rigidbody2D.isKinematic = true; gameOverUI.setScores(playerScript.score + 1f, highScore); gameOverUI.flyIn(true); //gameOverUI.flyIn(true); } renderer.material.SetFloat("_Percent", p * range + outerStartPercent); ticks += Time.deltaTime; if (!showingSmallRing) { if (ticks > interval) { ticks -= interval; // show the ring at starting state smallRing.SetActive(true); smallRing.renderer.material.SetFloat("_Percent", p * range + outerStartPercent); smallRing.renderer.material.SetFloat("_Emissive", startEmissive); startPercent = p * range + outerStartPercent; // set showing flag showingSmallRing = true; } } else { // update small ring state smallRing.renderer.material.SetFloat("_Percent", Mathf.Lerp(startPercent, targetPercent, ticks / moveTime)); smallRing.renderer.material.SetFloat("_Emissive", Mathf.Lerp(startEmissive, targetEmissive, ticks / moveTime)); // check stopping condition if (ticks > moveTime) { ticks -= moveTime; // hide the small ring smallRing.SetActive(false); // reset showing flag showingSmallRing = false; } } } }
// Update is called once per frame void Update() { // Debug.Log (gameOver); if (gameOver || gameWin) { return; } //if (Input.GetKeyDown(pauseKey)) { if (Input.GetButtonDown(pauseKey)) { if (!gamePaused) { oldTimeScale = Time.timeScale; Time.timeScale = 0f; gameOverScreen.pause(); gamePaused = true; } else { //Time.timeScale = oldTimeScale; // it will call Resume() indirectly gameOverScreen.resume(); } } if (gamePaused) { return; } if (isLerping) { lerpTo(destination); } if (gameOver || rigidbody2D.isKinematic) { return; } // if(rigidbody2D.IsAwake()) // { // rigidbody2D.Sleep(); // } /* * if (Input.GetKey (jump)) { * transform.rigidbody2D.AddForce (new Vector2 (50,jumpForce)); * } */ /* * if (Input.GetKeyDown(jump)) { * if (energy > enUsage * Time.deltaTime) { * transform.rigidbody2D.AddForce( * //new Vector2(50 * Time.deltaTime, jumpForce * Time.deltaTime)); * new Vector2(25, jumpForce)); * * energy -= enUsage * Time.deltaTime; * if (energy <= 0f) * energy = 0f; * } * } else { * energy += enUsage * 0.375f * Time.deltaTime; * if (energy > maxEN) { * energy = maxEN; * } * } * * float percent = energy/maxEN; * percent = Mathf.Sqrt(percent); * renderer.material.SetColor("_Color", * new Color(0f, percent, percent)); */ //if (Input.GetKeyDown (jump)) { hasJumped = false; if (Input.GetButtonDown(jump)) { if (jumpsLeft > 0) { hasJumped = true; Instantiate(shadow, transform.position, Quaternion.identity); //transform.rigidbody2D.velocity = new Vector2(transform.rigidbody2D.velocity.x,(0.5f+((0.5f/noOfJumps)*jumpsLeft)*jumpSpeed)); transform.rigidbody2D.velocity = new Vector2(transform.rigidbody2D.velocity.x, jumpSpeed); jumpsLeft--; foreach (Transform child in transform) { if (child.gameObject.activeSelf) { child.gameObject.SetActive(false); break; } } } } if (transform.position.y < -10f || transform.position.y > 15f || transform.position.x < -18f || transform.position.x > 18f) { //Application.LoadLevel (Application.loadedLevel); int songIdx = GameObject.Find("Control").GetComponent <ConfigLoader>().songIdx; float highScore = PlayerPrefs.GetFloat("HighScore_" + songIdx.ToString()); LevelText levelText = GameObject.Find("LevelGroup").GetComponent <LevelText>(); if (score + levelText.percent / 100f > highScore) { highScore = score + levelText.percent / 100f; PlayerPrefs.SetFloat("HighScore_" + songIdx.ToString(), score + levelText.percent / 100f); } gameOver = true; rigidbody2D.isKinematic = true; rigidbody2D.Sleep(); gameOverScreen.setScores(score + levelText.percent / 100f, highScore); gameOverScreen.flyIn(false); /* * int highScore = PlayerPrefs.GetInt ("HighScore"); * if (score > highScore) { * highScore = score; * PlayerPrefs.SetInt ("HighScore", score); * } * gameOver = true; * //Deactivating rigidBody * rigidbody2D.isKinematic = true; * rigidbody2D.Sleep(); * gameOverScreen.setScores (score, highScore); * gameOverScreen.flyIn (false); */ } }