How do I make that display the players health with UI? I'm trying to change the currentHealth into a string to display on the UI.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class HealthText : MonoBehaviour
{
public Text Health;
private PlayerInfo playerInfo;

// Start is called before the first frame update
void Start()
{
    playerInfo = this.GetComponent<PlayerInfo>();
}

// Update is called once per frame
void Update()
{
    Health.text = playerInfo.currentHealth.ToString(); 
}

}


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerInfo : MonoBehaviour
{

public int maxHealth = 100;
public int currentHealth;

public HealthBar healthBar;

// Start is called before the first frame update
void Start()
{
    currentHealth = maxHealth;
    healthBar.SetMaxHealth(maxHealth);
}

// Update is called once per frame
void Update()
{
    if(Input.GetKeyDown(KeyCode.Space))
    {
        TakeDamage(1);
    }
}

void TakeDamage(int damage)
{
    currentHealth -= damage;

    healthBar.SetHealth(currentHealth);
}

}

According to your script, this should work juste fine. There might be something wrong with your text object or your playerInfo. Try using playerInfo.currentHealth.ToString(“00”) and see if any number appears on the UI. if you see “00”, then your infoPlayer is bugged. If you don’t see anything there is a problem with the Text object (wrong font, not enough space, unsupported characters, etc…)

Juste a tip : you don’t have to call the text change on the Update methods, i suggest you juste change the text when the health actually changes, it will remain between changes and save you some performance.