Open JoyfulTora opened 2 years ago
Adds speed to the player so he can keep going with public float acceleration =10 ``` public float maxAcceleration = 10 to adjust the acceleration of the player. if (IsGrounded) ( float velocityRatio = velocity.x / maxVelocity: acceleration - maxAcceleration “ (1 - velocityRatio): velocity.x >= acceleration “ Time.fixedDeltaTime: if(velocity.x » = maxVelocity) f velocity.x - maxXvVelocity) This code works so that the Player can increase his speed on the Ground. “public float distance = 0' to see how far our player has walked.
Added UI for our score. Example, meter using text in the canvas. Player player: to declare objects from one script to another that we will use. Text distanceText, same as previously.
private void Awake() {player =GameObject.Find("Player").GetComponent
the goal is to use the Player and Distance Text components of an existing script.
void update() int distance = Mathf.FloorToInt(player.distance); distanceText.text = distance + " m"; to measure the distance traveled by the Player.
Adding Parallax background function so that we can make the background move left to right and looped so it looks as if the background is endless.
player = GameObject.Find("Player").GetComponent
Added the ground where the player is walking and the obstacle to block the player, which when the player is detected touching the obstacle it will be slowed down. The ground will spawn in front of the player and moves in the opposite direction of the character, pos.x -= player.velocity.x * Time.fixedDeltaTime; speed is adjusted to the player's velocity. For Obstacle will be spawned with GameObject box = Instantiate(boxTemplate.gameObject); float y = goGround.groundHeight; float halfWidth = goCollidder.size.x / 2 - 1; float left = go.transform.position.x - halfWidth; float right = go.transform.position.x + halfWidth; float x = Random.Range(left, right); Vector2 boxPos = new Vector2(x, y); box.transform.position = boxPos; object box will appear in the area according to the size of the existing ground.
dded UI, menus, and game over conditions. UI exits after player is in game over state { if(player.isDead) { results.SetActive(true); finalDistanceText.text = distance + " m"; } The Game Over Screen is used for when the game over condition is triggered, the Game Over Screen panel will pop up to the screen. We also display how far the player has traveled and the quit and retry buttons. if (player.isDead) { results.SetActive(true); finalDistanceText.text = distance + " m"; }
this is to show how far the player is after the game over condition is triggered.
public void Quit() { SceneManager.LoadScene("Menu"); when pressing the Quit button then we will exit the game. public void Retry() { SceneManager.LoadScene("SampleScene"); } when pressing the restart button then we will repeat the game from the beginning.
Issues i ran into: Death Menu Won't work properly despite the code has been typed properly. most likely its my unity version that messing it up because it working normally on my friends unity version
Having troubles with the sprites hence why the character and enemies are still a box, because sprites are glitching and i dont have an alternative sprites for it. so for now its just a box
Create a sprite square for the player. Add jump function in the script player and add velocity + gravity. public float gravity; public float Vector2 velocity; Add script “Input(GetKeyDown(KeyCode.Space))' to be able to use Space to Jump and add “Input.GetMouseButtonDown(0))" so that can use Left click on the mouse for the jump function. Determine its ground height uses "public float groundHeight = 10". Add jump velocity so players can stay in the air longer.