Last active
May 14, 2019 19:48
-
-
Save SenpaiRar/a46bbeaa138ce844f1175b21b81f73cc to your computer and use it in GitHub Desktop.
This script goes on the canvas that holds the gameplay UI elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
//Because UI is a seperate package from Unity as a whole, we have to import using the using command. | |
using UnityEngine.UI; | |
public class UIManager : MonoBehaviour { | |
//We create Text objects in our script. The text we created earlier will be dragged into this script through the editor. | |
public Text HealthText; | |
public Text WaterText; | |
public Text HungerText; | |
public Text AmmoText; | |
//Because we're displaying the different stats on the player, we need a source of information. We create a Player_Manager | |
//and Weapon_Parent object so we can drag them in through the editor and get the information | |
public Player_Manager Player_Stats_Source; | |
public Weapon_Parent Player_Weapon_Stats_Source; | |
void Update () { | |
//Every frame we get the numbers from the Player_Manager and Weapon_Parent and we set the text to the different numbers | |
//In this case, every frame we're setting the text to a prefix then the number, which has to use ToString() to make it text | |
HealthText.text = "Health:" + Player_Stats_Source.current_Health_Level.ToString(); | |
WaterText.text = "Water:" + Player_Stats_Source.current_Water_Level.ToString(); | |
HungerText.text = "Hunger:" + Player_Stats_Source.current_Hunger_Level.ToString(); | |
AmmoText.text = "Ammo: " + Player_Weapon_Stats_Source.currentAmmo.ToString(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment