void Update() { if (!isGameScreen || gameIsOver) { return; } if (!currentGift && !cameraIsMoving) { var cameraBounds = camera.OrthographicBounds(); currentGift = AddGift(); currentGiftCollider = currentGift.GetComponent <BoxCollider2D>(); var giftSpawnOffset = 1 + (currentGiftCollider.bounds.max.y / 2); currentGift.transform.position = new Vector3( 0, (camera.transform.position.y + cameraBounds.size.y / 2) - giftSpawnOffset, currentGift.transform.position.z ); } if (currentGift) { if (currentGift.GetCurrentState() == Gift.GiftState.SLEEPING) { var currentGiftHighestPoint = currentGift.GetHighestPoint() - groundLevel; if (currentGiftHighestPoint > currentHeight) { currentHeight = currentGiftHighestPoint; scoreText.text = GetCurrentScore(); // Store the highscore if (currentHeight > PlayerPrefs.GetFloat("Highscore", 0f)) { highscore = currentHeight; PlayerPrefs.SetFloat("Highscore", highscore); PlayerPrefs.Save(); } UpdateCameraPosition(); } currentGift = null; currentGiftCollider = null; } else if (currentGift.GetCurrentState() == Gift.GiftState.COLLISIONING) { var currentGiftHighestPoint = currentGift.GetHighestPoint() - groundLevel; if (currentGiftHighestPoint > highscore) { UpdateHighscoreBarPosition(currentGiftHighestPoint); } else { UpdateHighscoreBarPosition(highscore); } } } CheckGameOver(); }