Score based on collision

So this question is not really based on any of the courses, but I hope someone can help nonetheless.

I am working on my own game and one of the mechanics is that when the playerobject stops moving it gets a score based on its position … now I got the booleans for the movement trigger to work.

But I can’t get the score system to work.
I basically have put in boxcolliders with a tag attached to them in certain areas ( 4 values) and want to add a score based on a trigger .

The problem is that OnEnter and OnExit cannot be used as the player object can move in and out of several positions and OnEnter /OnExit do not communicate with each other.

OnStay is equally useless, but for different reasons as it keeps firing ( I just need one value, fired once per turn) and I found that I couldn’t compare tags in an if statement as it only takes the first "tag"in teh argument and negates the 2nd and it is important that I can use if logic to prune the values as the playerobject can be on teh border of any of these values and then it needs to take the lowest value.

SO I thought to write this code

   void CollisionMissery(Collision collision)
    {
     

       if (collision.gameObject.tag == "points15")
        {
            print("donkeyballs");
        }
                
        
    }

And place it behind a boolean if statement in update:

    if (scoreStart.StoppedMoving)
        {
            CollisionMissery();

        }

But I can’t get it to work … if I copy the values from the method I get red squirly lines …if I define the value I get a null reference exception … now I have been at it for a couple of days now so I am not seeing this clearly anymore, but I am at a point that I just want it to work, no matter how ugly or unconventional the code may be

Hi @MartinGames,

NullReferenceException means that a reference (“link”) to an instance is missing. Double click on the error message to see to which line in your code it is referring. If you exposed a field in the Inspector, make sure that it’s not empty.


See also:

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

Privacy & Terms