void Update() { alive = go.GetComponent <GameOverScreen>().alive; float scoreUpdate = 0; //Tick multiplier (Multiply by multipliers) multiplier = 1f; foreach (Upgrades.Upgrade id in _upgrades.CurrentUpgrades()) { if (id.IsMyName("multiplier")) { multiplier += id.Level(); } } foreach (MulStruct mul in new Dictionary <int, MulStruct>(_multis).Values) { mul._time -= Time.deltaTime; if (mul._time <= 0) { _multis.Remove(mul._location); } else { multiplier *= mul._mult; } } if (_foodFactor > 100) { butt.SetActive(true); FindObjectOfType <AudioManager>().play("EGM"); } //Update score by adding to old score if (alive) { scoreUpdate += _mv.GetCurrentSpeed() * Time.deltaTime * multiplier; score += Mathf.RoundToInt(scoreUpdate); } //Update highscore int oldHighScore = PlayerPrefs.GetInt("highScore"); if (score > oldHighScore) { PlayerPrefs.SetInt("highScore", score); if (!TheBoolThatTellsIfTheAnimationForANewHighScoreHasBeenPlayed) { anim.SetTrigger("high"); TheBoolThatTellsIfTheAnimationForANewHighScoreHasBeenPlayed = true; } } highScore.text = "High Score: " + PlayerPrefs.GetInt("highScore"); updateText(); }
// Update is called once per frame void Update() { speed = worldMoverReference.GetCurrentSpeed() / speedScaler; anim.speed = 1 + speed; }
// Update is called once per frame void Update() { isGround = isGrounded(); RaycastHit hit; if (Physics.Raycast(new Ray( new Vector3(player.bounds.center.x, player.bounds.center.y - player.bounds.extents.y + 0.001f, player.bounds.center.z + player.bounds.extents.z - 0.2f), Vector3.forward), out hit, player.bounds.extents.z + 2.0f)) { if (!hit.collider.gameObject.name.Equals("End")) { isGround = true; float ang = (Vector3.Angle(Vector3.up, hit.normal) * Mathf.Deg2Rad); Debug.DrawRay(new Vector3(player.bounds.center.x, (player.bounds.center.y - player.bounds.extents.y + 0.1f), player.bounds.center.z + player.bounds.extents.z), Vector3.forward, Color.cyan, 0.3f); //calculate requiered vertical velocity for current slope; if (ang < Mathf.PI / 4) { isGround = true; float boostUp = (Mathf.Tan(ang) * (WorldMoverref.GetCurrentSpeed() * Time.deltaTime)); player.Move(Vector3.up * boostUp); } } } if ((player.collisionFlags & CollisionFlags.Above) != 0) { Debug.Log("Hit Head"); } TouchPlot.SwipeDirection swipe = plot.GetSwipeDirection(25f); bool pressingLeft = Input.GetKeyDown(KeyCode.LeftArrow) || swipe == TouchPlot.SwipeDirection.LEFT, pressingRight = Input.GetKeyDown(KeyCode.RightArrow) || swipe == TouchPlot.SwipeDirection.RIGHT, pressingUp = Input.GetKeyDown(KeyCode.Space) || swipe == TouchPlot.SwipeDirection.UP, pressingDown = Input.GetKeyDown(KeyCode.DownArrow) || swipe == TouchPlot.SwipeDirection.DOWN; // Desiered Lane if (pressingLeft) { MoveLane(false); } if (pressingRight) { MoveLane(true); } //the direction of Desiered Lane Vector3 towards = Vector3.zero; if (desiredLane == -1) { towards += Vector3.left * LANE_DISTANCE; } else if (desiredLane == 1) { towards += Vector3.right * LANE_DISTANCE; } // Current Lane if (gameObject.transform.position.x > -0.1f * LANE_DISTANCE || gameObject.transform.position.x < 0.1f * LANE_DISTANCE) { currentLane = 0; } if (gameObject.transform.position.x < -0.9f * LANE_DISTANCE) { currentLane = -1; } if (gameObject.transform.position.x > 0.9f * LANE_DISTANCE) { currentLane = 1; } //actual vector that will perform move operation Vector3 moveVector = Vector3.zero; if (Mathf.Abs((towards - gameObject.transform.position).x) < closeEnoughToLane) //when close enough teleport, stops from overshooting! { gameObject.transform.position = new Vector3(currentLane * LANE_DISTANCE, gameObject.transform.position.y, gameObject.transform.position.z); } if (isGround) { verticalVelocity = -0.1f; isJumping = false; anim.ResetTrigger("Jump"); if (pressingUp) { verticalVelocity = jumpforce; isJumping = true; anim.SetTrigger("Jump"); } else if (pressingDown || slideFromAir) { verticalVelocity = 0.0f; slideFromAir = false; if (!isSliding) { StartSliding(); Invoke("StopSliding", 1.0f); } } } else { verticalVelocity -= gravity * Time.deltaTime; if (pressingDown) { verticalVelocity = -2 * jumpforce; slideFromAir = true; anim.ResetTrigger("Jump"); } } moveVector.x = (towards - gameObject.transform.position).normalized.x * speed; moveVector.y = verticalVelocity; player.Move(Vector3.right * moveVector.x * Time.deltaTime); if ((player.collisionFlags & CollisionFlags.Sides) != 0) { desiredLane = currentLane; } gameObject.transform.position = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, zedOrigin); player.Move(Vector3.up * moveVector.y * Time.deltaTime); Vector3 dir = transform.rotation.eulerAngles; if (dir != Vector3.zero) { dir.y = 0; dir.z = WorldMoverref.GetCurrentSpeed(); Vector3.Angle(Vector3.forward, dir); transform.forward = Vector3.Lerp(transform.forward, dir, 0.05f); } }