- Home /
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?
`
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.
Hi. Please, provide whole code (using pastebin.com for example). Code you provided is not enough to locate the error.
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.
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?!!
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'.
Tried it. Didn't work. Thanks for the solution though.
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.
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.
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
Your answer
Follow this Question
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