C# distance scoring system

I’m looking for some C# code to help me score distance from a point. Here’s the details:

I have a Ball on a Plane, my scoringSystem is in it’s own component and script.

I want the score to increase, on a scale, the more the ball is away from the center of the plane.

Finally, I need to check (IF statement, I’m thinking) that the Ball is touching the Plane, and if not then stop the score from increasing.

I’d like to do all of this within the scoringSystem script.


at the center of the plane you can anchor an empty GameObject that you just use for the transform location, then take the Vector3.Distance() of the two and use that for your score. As for the ball touching the plane, you can just do a short raycast down to see if you’re touching (raycast close enough so that it will only pick up the plane if you’re grounded).