Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Divinitize1 · Jan 24, 2020 at 06:49 PM · triggerpickuptwice

Trying to pickup an item via trigger, character has 2 collision boxes which are causing it to pickup twice.

I'm sure this question has been asked multiple times but I can't for the life of me word it correctly to find exactly what I need all of them seem to be related to other things.

I have a pickup object in the level with a trigger box. When my character enters the trigger it destroys the object and ++ the variable of the item. But because my player has both a circle and a box collider most of the time it's firing twice. Does anyone have a better way of doing things?

Again sorry if this is an obvious dupe I just can't seem to find what I'm looking for.

Comment
Add comment · Show 1
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 Divinitize1 · Jan 24, 2020 at 09:52 PM 0
Share

Very surprised that something like this isn't common for everyone making a 2d game... Still need help if anyone knows?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by HAndLol · Jan 24, 2020 at 10:13 PM

didnt you try to add a bool?

    //add a new bool
    bool done = false;

     //before anything check for your new bool
     private void OnTriggerEnter(Collider other)
     {
         if(!done){
             done = true;
     
             //do your code here
     
         }
     }
Comment
Add comment · Show 3 · 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 Divinitize1 · Jan 24, 2020 at 10:28 PM 0
Share

Seems a bit fiddly if dealing with multiple pickupable objects, or if there's multiple of that one object to collect.

avatar image Divinitize1 · Jan 24, 2020 at 10:37 PM 0
Share

Doing it this way seems to work out, however it seems unusual, must be a better way.

 void OnTriggerEnter2D(Collider2D other) 
     {
         if(other.gameObject.tag == "Gem")
         {
             if(!pickupDone)
             {
                 pickupDone = true;
                 Destroy(other.gameObject);
                 game.gems++;
                 game.UpdateText();
                 Invoke("ResetPickup",0.2f);
             }
         }
     }
     void ResetPickup()
     {
         pickupDone = false;
     }
avatar image HAndLol Divinitize1 · Jan 25, 2020 at 10:16 AM 0
Share

i dont know of any other way to do this @Divinitize1 ¯_(ツ)_/¯ thankfully this shouldnt be hard to research!

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

143 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Picking up items with Rigidbodies 2 Answers

Error CS0116 : A namespace can only contain types and namespace declarations. PLEASE HELP ME! 1 Answer

Ammo Pickup 0 Answers

How would I go about removing a mesh renderer component on collision with a trigger? 1 Answer

Audio Clip constantly play 1 Answer


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