- Home /
Question by
Rowz · Aug 19, 2016 at 01:22 PM ·
getcomponentobjectsreferencinghealthbarhealth-deduction
Self Reference and TextMesh inside of a script to change the text
I try to implement a health system and want to refere from my script HealthHandle wich is attached to the health prefab, to the TextMesh and change it to something else. The problem is when i do this i get the exception that the object is not assigned.
TextMesh tm;
// Use this for initialization
void Start () {
tm = gameObject.GetComponent<TextMesh>();
}
public void decrease ()
{
if (current() > 1)
{
tm.text = tm.text.Remove(tm.text.Length - 1);
}
else
{
Destroy(transform.parent.gameObject);
}
}
what im doing wrong here?
the function decrease gets called from another script like this:
public HealthHandle healthHandle;
healthHandle.decrease();
the Object that Contains the HealthHandle is atached in the unity editor
Comment