Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Lære Game Improvement | Unity Physics
Unity for Beginners
course content

Kursusindhold

Unity for Beginners

Unity for Beginners

1. Unity Introduction
2. Write your First Script
3. Unity Physics
4. Unity UI and Sounds
5. Polishing and Export your Game

book
Game Improvement

This is the code to make our player come back at it's start position when he lost so let's explain it:

cs
  1. Vector2 startPosition: this line declares a variable startPosition of type Vector2. It will store the initial position of the player;

  2. private void Start(): this method is called when the game starts. It assigns the current position of the player to startPosition, effectively saving the starting position;

  3. void playerLost(): this custom method is triggered when the player loses. It resets the player's position to the saved startPosition, stops any movement by setting velocity to zero, and logs a message "You lost" to the console.

cs

Var alt klart?

Hvordan kan vi forbedre det?

Tak for dine kommentarer!

Sektion 3. Kapitel 5
Vi beklager, at noget gik galt. Hvad skete der?
some-alt