Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Health Percentage?

Discussion in '2D' started by JuiceBox, Feb 7, 2015.

  1. JuiceBox

    JuiceBox

    Joined:
    Jan 24, 2015
    Posts:
    41
    Hey everyone, I was wondering if it was possible to do something like a health percentage? I'm completely new to Unity so this is probably super easy to do. If you don't know what I'm talking about, I made a mock-up image of what I mean.
    It Looks a bit like a life system, but not a live system. So yea, I was just wondering how I'd be able to do something like this. Thanks in advanced! ^ -^
     
  2. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    U can say more details ?
     
  3. JuiceBox

    JuiceBox

    Joined:
    Jan 24, 2015
    Posts:
    41
    What I mean is a Health System that draws how much health you have but with numbers. Let's say I have a HP variable and it is set to 8, the health thing would say "HP: 8" or something.
     
  4. David James

    David James

    Joined:
    Jan 29, 2015
    Posts:
    61
    U can use health bar , with HP 100/100

    like this demo ?
     
  5. boolfone

    boolfone

    Joined:
    Oct 2, 2014
    Posts:
    289
    I made a video demonstrating how to do this:



    It uses this script, which is attached to a text object:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class ModifyText : MonoBehaviour {
    6.  
    7.     int health = 0;
    8.  
    9.     // Use this for initialization
    10.     void Start () {
    11.  
    12.     }
    13.  
    14.     // Update is called once per frame
    15.     void Update () {
    16.         health = (health+1) % 101;
    17.         Text text = this.GetComponent<Text>();
    18.         text.text = "Health: " + health;
    19.     }
    20. }