• 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 sheiro · Jun 11, 2015 at 10:44 AM · itemcollect

Coullecting Item sometimes counts double

Hi, now i made my first gamedemo with unity and everything worked fine, except a problem with collecting items. I have an onTriggerEnter function that, when triggerd, counts the number of items the player found. The problem is, that while collecting the item, the function sometimes adds 1 and sometimes adds 2 to the score, and i didn`t manage to solve that problem yet. I assume that it has to do with some update function, so that the game runs to fast, and the onTriggerEnter function could not deal with it. The code for the function is simple, so i don`t think that`s the problem:

 function OnTriggerEnter(other:Collider)
 { 
     if (other.tag == "Artifact") 
     {     
     Destroy(other.gameObject);
     
     ScoreManager.Artifacts += 1;  
     
     blink = true;
     
 //    var audio2 = GetComponent.<AudioSource>();
 
     audio2.Play();
     } 
     
 } 

Maybe someone else had the same problem, or knows a solution? Any comment would be helpful!

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 Ekta-Mehta-D · Jun 11, 2015 at 10:51 AM 0
Share

It might be triggering 2 times.

avatar image LoadStar · Jun 11, 2015 at 01:27 PM 1
Share

You should say that as an answer then. It could help other people in the future who have the same problem.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by sheiro · Jun 11, 2015 at 12:17 PM

Sorry, i found the problem. I`m using 2 Colliders, one as an trigger, the other for physics. My bad :/

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Enable an area after a condition is met 2 Answers

A few thinks I need for this game 0 Answers

Resouce script help 3 Answers

Android Game crashing when collecting collectibles 0 Answers

Do 2 Triggers Collide? 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