Hitting obstacle does not increase Hit score

Whenever I bump into a particular obstacle it does not increase my hit score while other obstacles do.

As you can see the highlighted obstacle does not increase the hit score. All the black game objects mean that I have bumped into them.
Here is its inspector.
image_2022-01-13_134541

Here are scripts in use:-




Scorer

Hi Mehtab,

Please note, it’s better to copy/paste your code and apply the code fencing characters, rather than using screenshots. Screenshots are ideal for displaying specific details from within a game engine editor or even error messages, but for code, they tend to be less readable, especially on mobile devices which can require extensive zooming and scrolling.

You also prevent those that may offer to help you the ability to copy/paste part of your code back to you with suggestions and/or corrections, meaning that they would need to type a potentially lengthy response. You will often find that people are more likely to respond to your questions if you make it as easy as possible for them to do so.

Regarding your problem, it might be that the method in ObjectHit gets called before the method in Scorer. In that case, the tag would already be “Hit” even though the score has not been added yet.

What you could try is to rename the OnCollisionEnter method to OnCollisionExit. And if that did not fix it, rename the method OnCollisionEnter again, then add the ObjectHit and Scorer to the “script execution order” list. The Scorer must come first, then the ObjectHit. The values in the list define the order. They do not have anything to do with seconds or something like that.

Hope this helps :slight_smile:


See also:

1 Like

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

Privacy & Terms