- Home /
Deactivated Targets in Shooting Game Cause Score to Never Stop Adding One
So basically i have this shooting game where when targets get shot 3 times the game object for the target is deactivated but in another script i want it to know when each target is deactivated so that i can add one to the score. I got that to work except since each target is deactivated and stays deactivated it continuously adds one every update for every deactivated target. I currently have it set up as an array of targets in the script and every update it sees if the target is deactivated, if so it adds one to the score but it never stops.
private void Score()
{
for (int i = 0; i < Targets.Length; i++)
{
if (!Targets[i].activeInHierarchy)
{
score++;
}
}
}
Answer by Thomas-Hawk · Jan 24, 2017 at 05:22 PM
i would have "did you hit them" or "did their HP go to 0" as the "+1". otherwise, it's going to count one, for each deactivated one, every time.
Your answer
![](https://koobas.hobune.stream/wayback/20220612105451im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to deactivate gameObjects instead of destroying them ? 1 Answer
Game Object Chains 1 Answer
Is there a decent tutorial for a local high score table (android)? 1 Answer
Filling array with gameObjects 2 Answers
GameObject Array in Editor GUI 3 Answers