diff --git a/~Documentation/images/CanvasCreation.png b/~Documentation/images/CanvasCreation.png new file mode 100644 index 0000000..ae7dc12 Binary files /dev/null and b/~Documentation/images/CanvasCreation.png differ diff --git a/~Documentation/images/Final.gif b/~Documentation/images/Final.gif new file mode 100644 index 0000000..e69de29 diff --git a/~Documentation/images/FitBackgroundToScreen.gif b/~Documentation/images/FitBackgroundToScreen.gif new file mode 100644 index 0000000..c274c54 Binary files /dev/null and b/~Documentation/images/FitBackgroundToScreen.gif differ diff --git a/~Documentation/images/FitImageToScreen.png b/~Documentation/images/FitImageToScreen.png new file mode 100644 index 0000000..2ce1216 Binary files /dev/null and b/~Documentation/images/FitImageToScreen.png differ diff --git a/~Documentation/images/GameOverScreen.png b/~Documentation/images/GameOverScreen.png new file mode 100644 index 0000000..6f37099 Binary files /dev/null and b/~Documentation/images/GameOverScreen.png differ diff --git a/~Documentation/images/GameOverWorks.gif b/~Documentation/images/GameOverWorks.gif new file mode 100644 index 0000000..d599c2d Binary files /dev/null and b/~Documentation/images/GameOverWorks.gif differ diff --git a/~Documentation/images/HiddenCanvas.gif b/~Documentation/images/HiddenCanvas.gif new file mode 100644 index 0000000..a8725d7 Binary files /dev/null and b/~Documentation/images/HiddenCanvas.gif differ diff --git a/~Documentation/images/Unity_DlfCdNGIvo.gif b/~Documentation/images/Unity_DlfCdNGIvo.gif new file mode 100644 index 0000000..06cd583 Binary files /dev/null and b/~Documentation/images/Unity_DlfCdNGIvo.gif differ diff --git a/~Documentation/images/Unity_pa5PhRZaqJ.gif b/~Documentation/images/Unity_pa5PhRZaqJ.gif new file mode 100644 index 0000000..e69de29 diff --git a/~Documentation/images/ValuesUsedByUI.png b/~Documentation/images/ValuesUsedByUI.png new file mode 100644 index 0000000..8d3d2cc Binary files /dev/null and b/~Documentation/images/ValuesUsedByUI.png differ diff --git a/~Documentation/topics/Opgave-2-UI.md b/~Documentation/topics/Opgave-2-UI.md index b85b530..6d0ede5 100644 --- a/~Documentation/topics/Opgave-2-UI.md +++ b/~Documentation/topics/Opgave-2-UI.md @@ -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 \ No newline at end of file +* Opdater en tekst i UI'et til at matche antal liv + +![Unity_DlfCdNGIvo.gif](Unity_DlfCdNGIvo.gif) \ No newline at end of file