Score is not adding correctly

Hello,
I am having issues with the scoring being added wrongly to the game. Instead of 83 being added to my game after every collision it is adding 166 each and every time. I have checked everything in my project but cannot find the reason this is happening. I first had the AddToScore() function getting called differently in the block class but then changed it to how it was done in the lecture in the hope it would fix the error, but sadly it did not work.

Hi,

Have you checked your Inspector? The values in the Inspector override the default values at the top of of your class.

Add a Debug.Log with a meaningful message to see how many times the collision method gets called per collision.

So both the score counter and the block breaking gets called twice every time the ball hits a block. so I have 146 blocks on the first level and after hitting one block I have 144 blocks left and have 166 points. Any ideas on how I would fix this?

Does the ball hit the same block? Check that by logging the instance id of the other game object (= the block) into your console with GetInstanceID().

How many Block scripts does a block have attached? And how many colliders?

Is the Collision Detection of the ball’s Rigidbody2D set to “Continuous”?

Have you already compared your code to the Lecture Project Changes which can be found in the Resources of this lecture?

Thanks for the tips, I was so lost. It was that I had two box collides on the blocks.

You’re welcome. :slight_smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms