Unity UI for Collectable Items
Create an UI object
Comes with a canvas object. the Text object will be created as a child object to the canvas.
- canvas
how to display the text
- reference resolution: choose the biggest one
- UI Scale Mode: scale with screen size
- text
set up your own test config
- font size
- Color
- anchor preset (for different resolution)
Coding
- Player class stores an integer as a counter
int coinsCollected
- Player class stores a reference type Text to the UI text component
Text coinsText
In the player object
1 | // get coin status at the beginning |
In the collectable object
1 | private void OnTriggerEnter2D(Collider2D collision) |