PlayerStats Version1
Last updated
Last updated
This project1 will use a UI-Panel with 2 children: UI-Text elements to display the score and health values that are stored in the GameData component. Note: Required updates for GameData - V2
Steps Create GameObjects:
UI-Panel: ScorePanel
UI-Text: ScoreText
UI-Text: HealthText
Directions: 1. Add A UI-Panel Element to the Hierarchy, 2. Name it: ScorePanel. 3. If these are the first UI elements added to the Scene, follow the directions to configure the Canvas RenderMode
Canvas - the parent GameObject for all UI elements
Panel - used here as a container for 2 UI-Text elements
EventSystem - manages UI event-handling - if UI events don't seem to be working, make sure that one of these components is in the Hierarchy.
When any additional UI elements are added to the Hierarchy, the Canvas will be the parent element.
Modify the Canvas's RenderMode, set it to 'Screen-space Camera', and select the Main-camera as the render camera
Resize the Panel and Use the Rect-Transform component to set the Panel's anchors to the top of the canvas.
Add UI-Text element as a child: name it: ScoreText
Use Rect-Transform Component panel to set the anchors of the ScoreText so it is aligned to the Middle-Right Side of the ScorePanel.
Add UI-Text element as a child: name it: HealthText
Use Rect-Transform Component panel to set the anchors of the HealthText so it is aligned to the Middle-Left Side of the ScorePanel.
Attach the PlayerStats.cs script to the ScorePanel gameObject.
Populate the Inspector fields: ScoreText and HealthText in the Inspector using the ScoreText and HealthText GameObjects.
Optionally add a CanvasGroup component if you want to hide the PlayerStats Panel prior to MiniGameState.active state. Logic needs to be added for this functionality
The images show the ScorePanel has 2 UI-Text gameObjects as children in the Hierarchy Panel. The ScorePanel is anchored using Stretch-Top setting in the Rect Transform component. The ScoreText has it's Rect Transform set to Middle-Right, as defined relative to it's Parent - the ScorePanel The HealthText has it's Rect Transform set to Middle-Left, as defined relative to it's Parent - the ScorePanel
The image below shows that Also, the HealthText and ScoreText gameObjects have been used to populate the corresponding fields in the PlayerStats script component.