I want to display the player’s current health level as a number on a ui text component, how would I modify the player’s health script to display the health float variable on a ui text
var PointCube : Transform;
var spawneffect : Transform;
var deatheffect : Transform;
var SpawnPoint : Transform;
var respawn : boolean = false;
var health:float = 90;
First you need to add var healthText : UI.Text; as a new variable to your script, this will create a new public var for a UIText which allows to you simple assign a UI → Text Object to your script. After doing so and saving the changes a box should appear in your script properties in the inspector.
Now Create a new Game Object → UI → Text (this will automatically create a canvas if you dont have one selected in the Hierarchy) and assign it to Health UI. After that you can change the content of the Text field in your script with the following code:
HealthText.text = "Health: " + health;
This code would make it display “Health: 90” if the health var is 90. Of course you always need to execute this code when health changes otherwise the health wont update. So either add it to the Update function or a function which is called whenever your character takes damage.
EDIT: Sorry i was mixing up GUI with UI which of course wont work. This way it should work.