Help guys.
I have a prefab with a TextMesh component attached to it as well as a script to alter the text.
when an enemy is killed, the prefab is instantiated showing hit points.
But i have no idea how to make certain enemies have different points for the textprefab.
I tried setting a value on each enemy which will then be attributed to the script on the textPrefab instantiated by the enemy, but it is all a mess.
I’m new also but ill give this a shot since no one else has said anything yet. You may already have tried the code below, maybe post some sample code of what you have tried already if this idea doesn’t help.
Prefab Script:
public class PrefabScript : MonoBehaviour
{
public void ShowHitPoints(int displayValue)
{
GetComponent<TextMesh>().text = displayValue.ToString();
}
}
Enemy:
...
public GameObject textPrefab;
protected int hitPoints = 5;
public void Die()
{
GameObject go = Instantiate(textPrefab);
go.GetComponent<PrefabScript>().ShowHitPoints(hitPoints);
}