- Home /
Mesh Renderer not always disabling
Hello, I am trying to disable a MeshRenderer displaying text when health on the parent object reaches 0. This seems to work when the GameController class first instantiates it and then sets its health (in the Start() method), but it does not work later on when the parent object itself detects that it has 0 health.
private int health;
public int Health { //Property.
get {
return health;
}
set {
health = value;
actOnHealth ();
textMesh.text = "" + health;
}
}
private void actOnHealth ()
{
if (health <= 0) {
print ("health<=0,removing render");
GetComponentInChildren<MeshRenderer> ().enabled = false;
}
}
When the game is running, and when it is supposed to disable the MeshRenderer, it prints the message saying the health<=0, but the MeshRenderer stays enabled.
Am I doing something wrong here, doing something that is just not possible? It really looks like a bug to me, I have no clue what is going wrong.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
c# not going to destination on 0 hp 1 Answer
Footstep Script Not Working 2 Answers
Script error help! 1 Answer