The score still getting hits after the object turn on tag "Hit"


Maybe I’m missing something, but I do get the block to turn red AND change it’s tag from Untagget to Hit, but the Debug.Log keep printing hits, even when the cube drops and hit the ground.

The player object is correctly tagged as Player.

I’m at a lost here. Anything I’m missing?

Thanks!

Hi,

Welcome to our community! :slight_smile:

Add another Debug.Log to the OnCollisionEnter method of the Collisions class. Then play your game again. Maybe the methods get executed in the wrong order. In that case, you’ll have to add the two scripts to the Script Execution Order list:

  • Scorer
  • Collisions

Did this help you fix the problem?


See also:

Can you add more Debug.Log() information, like at least one in the OnCollisionEnter of Collisions so we can get a better feel for the order in which things get called

Hi! I did a little recorder of the estate of the game and attached screenshots for the hierarchy!

Game code - https://youtu.be/DYg4L8SNneo

Player
image
Obstacle

Ok, at time 0:05 in the video, we can clearly see that the Scorer script is on the dropper object.

That means that as the player interacts with it, the code

if (other.gameObject.tag != "Hit")

will always be true, because other in the case is Player, and Player’s tag is “Player” (i.e. not “Hit”), hence the statement is true.

I do not know if you meant for Scorer to be placed on the Dropper object, so you have two possible fix (depending on what you’re trying to do):

  1. Attach Scorer to Player, and not to Dropper

  2. Leave Scorer on Dropper (if that was the intention), but replace the if condition

// before
if (other.gameObject.tag != "Hit")

// after
if (gameObject.tag != "Hit")

Hope that helps

Hi!

It did. I attached the Scorer to the player, and it started counting the hits on the console!

I wanted to limit the counting to only the first hit, and not add a Hit every time they touched, but I can totally n work with this. :stuck_out_tongue:

Thank you!

1 Like

Does that mean the problem is solved, @Gagz9k? :slight_smile:


See also:

Yes! Sorry for the late reply. Forgot to check back. Thank you both for the suggestions :smiley:

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

Privacy & Terms