Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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 CatKillen · Feb 16, 2014 at 06:29 PM · collider2dontriggerenterincrement

Why does this increment by 2?

The object collides with the player, turns invisible, plays the particle, then increases the score based on the object's color.

However, it increases yellowcount, bluecount, etc., by 2 instead of by 1 (same if it's yellowcount += 1). Happens on the first frame of collision. Also happens if it's OnTriggerExit2D.

     void OnTriggerEnter2D(Collider2D other)
     {
         if (other.tag == "Player")
         {
             renderer.enabled = false;
             particle.Play();
 
             switch (flagColor)
             {
                 case 0: //yellow
                     score.yellowcount++;
                     break;
                 case 1: //green
                     score.greencount++;
                     break;
                 case 2: //blue
                     score.bluecount++;
                     break;
                 case 3: //red
                     score.redcount++;
                     break;
             }
         }
     }
Comment
Add comment · Show 2
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
avatar image CatKillen · Feb 16, 2014 at 07:12 PM 0
Share

Awesome, yep! It's incrementing by the amount of active flags of that color. Thanks!

avatar image Christian.Tucker · Feb 18, 2014 at 09:55 AM 0
Share

Not really an answer, but more of a comment. I personally believe it's a better practice to see when the player collides with an object, not when an object collides with the player. It simplifies things during more advanced development. It also reduces the amount of instances (links) to the score script you would need, increasing performance.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by thaiscorpion · Feb 16, 2014 at 06:56 PM

I can't see any issue with that script that would produce this. I had a similar issue and it was because I had the script added twice in the scene so it did the calculations two times.

Comment
Add comment · Show 2 · 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
avatar image CatKillen · Feb 17, 2014 at 12:39 AM 0
Share

well, I removed all other instances calling the script. Just the player and one flag with an empty game object holding the score. It's going up by 2. It's maddening.

avatar image thaiscorpion · Feb 18, 2014 at 09:22 AM 1
Share

Add a Debug.Log in each case and check if it is being executed twice. If so then you must have the script twice or something :D

avatar image
5

Answer by POLYGAMe · Feb 18, 2014 at 09:53 AM

Check that your player doesn't have more than one collider (possible child objects?) with the Player tag. Each one will trigger the code.

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.

Follow this Question

Answers Answers and Comments

22 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Enable Specific Collider when Another is Triggered. 1 Answer

Best practice for checking which object has collided. 2 Answers

How to work with tags ? 1 Answer

Checking if a single object's trigger is entered out of a group of identical objects? 1 Answer

Is It Possible to Detect a Collision Within a Canvas? 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges