Problem with the scorer

Everything works fine and I don’t even get an error, but when I add the if statement for the scorer it doesn’t show anything in the console. Anyone knows why?

public class Scorer : MonoBehaviour
{
int hits = 0;

private void OnCollisionExit(Collision collision)
{
    if (collision.gameObject.tag != "Hit")
    {
        hits++;
        Debug.Log("you bumped into a thing this many times: " + hits);
    }
}

}

Hi Atefeh,

Welcome to our community! :slight_smile:

Thanks for mentioning what you’ve already figured out. That’s helpful. Your if-statement asks ‘Is the tag of the other game object not “Hit”?’. Since you are not getting the message in your console, that tag might be ‘Hit’.

Do you change the tag somewhere in your code? If so, try to rename this method here to OnCollisionEnter and the other one to OnCollisionExit. Then test your game again.

Did this work?


See also:

1 Like

Thank you, Nina! I changed the OnCollisionExit/Enter and it worked!

Fantastic! :slight_smile:

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

Privacy & Terms