Ammo and Health Display - Dynamic UI

shoot.cs

Size: 3.43 KB

You need to login to download this file.

Script

  1. Add 3 new variables
    1. Current Status
    2. Max Status
    3. Public Text Object
  2. Add in the beginning, in the Start function
    1. currentStatus equal to maxStatus
  3. Additionally, include a text object and assign the ‘currentStatus’ variable to it
AmmoText.text = currentAmmo.ToString(“Ammo: “ + currentAmmo);
  1. If an event occurs, update the ‘currentStatus’ by either decrementing (--) or incrementing (++) it also update the text
currentAmmo--;  or  currentAmmo++;
  1. To update the text just add this line again
AmmoText.text = currentAmmo.ToString(“Ammo: “ + currentAmmo);
  1. To reset, simply set ‘currentStatus’ back to ‘maxStatus’ and add the text field again

 

UI

  1. Create a new UI Text element
    1. UI – Legacy – Text

  1. Remove the text

Unity UI Text - Javatpoint

  1. Relocate the text field

Combining

  1. Place your text object in the empty text field within you script

recommended