• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by KyleAB11 · Jan 24, 2017 at 04:32 PM · arrayscoregameobjectsdeactivate

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++;
             }
         }
     }


Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

How to deactivate gameObjects instead of destroying them ? 1 Answer

After days of looking for solutions, what's wrong with my array script? 2 Answers

I'm new to Unity and attempting to create an infinite array of cubes. How would I go about doing this? 0 Answers

Sorting an array - C# 3 Answers

Using a number array? 1 Answer

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges