(Updated for RFPS 1.23)

Realistic FPS Prefab (by Azuline Studios) uses a GUIText prefab to display health as a text string. This article describes how to replace it with a Unity UI health bar.

1. Add a Unity UI slider named “Healthbar”.

2. Edit HealthText.cs. In the variable section,  add the line containing “//[PixelCrushers]”:

    public bool showNegativeHP = true;
    private UnityEngine.UI.Slider slider; //[PixelCrushers] Our Unity UI healthbar.

3. In the Start method,  add the 2 lines containing “//[PixelCrushers]”:

    void Start(){
        var sliderGO = GameObject.Find("Healthbar"); //[PixelCrushers]
        slider = (sliderGO == null) ? null : sliderGO.GetComponent<UnityEngine.UI.Slider>(); //[PixelCrushers]
        ...

4. In the Update method, add the line containing “//[PixelCrushers]”:

    void Update (){
        //only update GUIText if value to be displayed has changed
        if(healthGui != oldHealthGui || oldWidth != Screen.width){
            if (slider != null) slider.value = Mathf.Clamp(healthGui / 100, 0, 1); //[PixelCrushers]
            ...