Skip to content

Commit

Permalink
Everything done?
Browse files Browse the repository at this point in the history
  • Loading branch information
Daxode committed Jul 14, 2024
1 parent 719e5d5 commit 1ab0d1d
Show file tree
Hide file tree
Showing 11 changed files with 65 additions and 4 deletions.
Binary file added ~Documentation/images/CanvasCreation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added ~Documentation/images/Final.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/FitBackgroundToScreen.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/FitImageToScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/GameOverScreen.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/GameOverWorks.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/HiddenCanvas.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/Unity_DlfCdNGIvo.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added ~Documentation/images/ValuesUsedByUI.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 65 additions & 4 deletions ~Documentation/topics/Opgave-2-UI.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,74 @@

## Lav Game Over Canvas

GameObjekter er som standard disabled, men man slår den til
For at lave UI i Unity, så skal man bruge et Canvas. Det kan laves som set herunder

![CanvasCreation.png](CanvasCreation.png)

I samme billede kan du også se hvordan man laver en tekst, som kan bruges til at vise Game Over. (hedder: `Text - TextMeshPro`)

Tænker at bruge den viden til at lave denne skærm:

![GameOverScreen.png](GameOverScreen.png)

Dens struktur kan ses her:
* Canvas
* Game Over (background)
* GameOver Text
* Reset Text

For at lave baggrunden, kan man bruge en `Image Raw` og vælge en farve.
Dog er det vigtigt at man kan ændre mode til `stretch` for både x og y aksen, så det fylder hele skærmen.

![FitImageToScreen.png](FitImageToScreen.png)

Se hvordan det ser ud i spillet:

![FitBackgroundToScreen.gif](FitBackgroundToScreen.gif)

Værdier vi bruger:

![ValuesUsedByUI.png](ValuesUsedByUI.png)

Planen er at denne tekst skal være skjult indtil spilleren dør. Dette kan gøres ved at disable objektet i Unity:

![HiddenCanvas.gif](HiddenCanvas.gif)

## Score for at dræbe fjender

1. Lav tekst
2. Lav `public` variable i dræb enemy script
Tilføj så at hvis spilleren rammer en fjende, så aktiveres Game Over Canvas
```C#
public GameObject gameOverScreen;

void OnCollisionEnter(Collision other)
{
if (other.gameObject.CompareTag("Enemy"))
{
gameOverScreen.SetActive(true);
}
}
```

![GameOverWorks.gif](GameOverWorks.gif)

## Reload Scene

Ofte er det nice at kunne genstarte spillet, dette kan gøres ved at genindlæse scenen.

På klassen `SceneManager` i Unity er der en metode `LoadScene` som kan bruges til at genindlæse scenen.

```C#
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
SceneManager.LoadScene("GameScene");
}
}
```

## Opgave
* Tilføj liv variable til spilleren
* Opdater en tekst i UI'et til at matche antal liv
* Opdater en tekst i UI'et til at matche antal liv

![Unity_DlfCdNGIvo.gif](Unity_DlfCdNGIvo.gif)

0 comments on commit 1ab0d1d

Please sign in to comment.