How to update counter from a different gameobject's script?
I'm making a RTS game.
I have a unit attribute script on the prefab of the unit, and a script on a user canvas interface that keep track of all the units being built via counter (int).
The problem i'm running into is that the unit attribute script on the prefab handle the health and destruction of that specific unit. So if that unit reach 0hp it's going to be destroyed, but I can't seem to get it to update the counter from the other script.
I've tried
Private UnitCount unitC;
unitC. GetComponent(typeof(UnitCount)).GetComponent().totalUnit -- ; which doesn't work and return
an error "there isn't any instance of the object"
also tried the GetComponentInParent or InChild.
i've also tried,
start(){
unitC = GetComponent();
}
destroy(){
unitC.totalUnit --; it doesn't return an error, but it's stuck in an infinite loop not knowing where to go.
}
is there a different way around this ?
Your answer
Follow this Question
Related Questions
How to move camera in x-z axis only for RTS touch script for mobile ? 0 Answers
Animate RTS building with worker 0 Answers
Trying to disable gameobjects depending on what number an int is, How would I go about doing this? 0 Answers
Raycast2D not working like it should be. 0 Answers
How could I increment numbers every 1000th of a second? 4 Answers