How can I add text on object by script?

Hello,
I want to add health number on card object, but I don’t know how to make this text follow it. I want make that text attached to it, but I don’t know how to write it. My code:
using UnityEngine;
using System.Collections;

public class HealthScript : MonoBehaviour {
	public int maxHealth = 10;
	public int curHealth = 10;

	void Start () {
	
	}

	void Update () {
		AddjustCurrentHealth(0);
	}

	void  OnGUI () {
		GUI.Label (new Rect (20, 40, 50, 20), curHealth + "/" + maxHealth);
	}



	public void AddjustCurrentHealth(int adj) {
		curHealth += adj;
		
		if (curHealth < 0)
			curHealth = 0;
		
		if(curHealth > maxHealth)
			curHealth = maxHealth;
		
		if(maxHealth < 1)
			maxHealth = 1;
	}
}

I would appreciate any help/instructions. :slight_smile:

It sounds like you are asking how to do script A to script B interactions? In script A, add

public HealthScript healthScript;

then drag/drop that reference to the GameObject this is attached to in the Inspector; then reference curHealth as

heathScript.curHealth

There are a thousand examples on this topic already showing alternatives too; please search UA/Google.

If this is not what you are asking, you need to be clearer (what’s a card object? what does make text follow mean?, etc)