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 abssuper20 · Jul 08, 2018 at 07:52 AM · unity 5buttonscore system

Score Count Bug

So i'm creating a pickup system where when i collect the pickup, it is destroyed and the score should increase by 1. But when i collect the pickup the score somehow increases by 2. And this only happens if i destroy the pickup. If i use gameObject.SetActive(false) to deactivate the pickup then the score increases by 1 like it should. So why is this happening? alt text`

capture.png (36.5 kB)
capture1.png (42.8 kB)
Comment
Add comment · Show 4
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 MT369MT · Jul 08, 2018 at 09:00 AM 0
Share

Hi, this is strange and i don’t see errors in your code. Try to add a Debug.Log after the ui.count++; line so you know if it is called only once or twice.

avatar image Perfecter · Jul 08, 2018 at 10:31 AM 0
Share

Hi. Please, provide whole code (using pastebin.com for example). Code you provided is not enough to locate the error.

avatar image abssuper20 Perfecter · Jul 08, 2018 at 11:59 AM 0
Share

Don't worry. The rest of the code doesn't even interact with the pickup system. i triple checked before posting the question and the photos.

avatar image abssuper20 · Jul 11, 2018 at 04:18 AM 0
Share

Hey guys a weird update. For some reason i tried to use destroy again and this time, surprisingly it's working. The counter is incrementing by one like it should. And shockingly i didn't even change the code a bit apart from using destroy rather than setactive. Weird right?!!

3 Replies

· Add your reply
  • Sort: 
avatar image
-1

Answer by Ermiq · Jul 08, 2018 at 11:46 AM

Maybe you should try '++ui.count' instead of 'ui.count++'. Also, I prefer to use 'ui.count += 1'.

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 abssuper20 · Jul 08, 2018 at 12:01 PM 0
Share

Tried it. Didn't work. Thanks for the solution though.

avatar image abssuper20 · Jul 08, 2018 at 12:55 PM 0
Share

Ok apparently now i'm facing the same issue again and after debug.log it appears that OnCollisionEnter is called once perfectly but OnTriggerEnter is being called twice.

avatar image
0

Answer by Tobychappell · Jul 08, 2018 at 11:53 AM

From Unity Docs:

it will destroy the GameObject, all its components and all transform children of the GameObject. Actual object destruction is always delayed until after the current Update loop, but will always be done before rendering

Could be a syncing issue which may need a work around like telling the colliers to ignore eachother

Or you really are coming into contact twice.

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

Answer by abssuper20 · Jul 08, 2018 at 12:05 PM

Hey Guys i found the problem and it was a pretty silly one. The OnTriggerEnter code was attached to the player but i hadn't enabled the "is Trigger" on the player itself. Instead i had enabled it on the pickup. :p

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

187 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 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

How do I control the behavior of Android soft buttons (Immersive mode)? 1 Answer

How to know if Unity UI button is being held down? 0 Answers

Add Listeners to array of Buttons 2 Answers

Score is decrementing twice while passing through a collider. 1 Answer

GUI button doesn't appear on Android 0 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