# Pointlight changing colour with distance

Okay I’m a total noob so if you decide to help me just treat me as a very simple child. I’ve completed a Pong game as part of a tutorial and I’m interested in playing around with it, I’ve added a point light to the ball so it has a basic glow but I was wondering how to go about making it fade to a different colour in proximity to the player and enemy paddles and then fade back when the ball bounces away.

Giving me the script won’t teach me anything so I was hoping for some sort of pseudo-script or something to point me in the right direction. So far I’ve played with using Mathf.PingPong from the Unity manual to fade the colour, I just need it to be distance based. Things like raycasting (if that’s applicable here) are waaaay out of my league for the moment!

Someone who doesn’t want a script. How refreshing.

• Get access to the paddles inside the ‘ball’ script. You can add a public game object or transform at the top of the ‘ball’ script and drag and drop the paddles onto the variables. Or you can use private variables and use GameObject.Find() to get access. See Accessing Other Game Objects. for more info.
• Calculate the distance to each paddle from the ball. One way is to use Vector3.Distance().
• Calculate a fraction between the paddles. The calc will be something like "distance1 / (distance1 + distance2).
• Create and set two color variables, one for each paddle. If you make them public (default in Javascript), you can set the color in the inspector, or you can directly assign the color in script.
• Use Color.Lerp() to generate the color.
• Assign the color to the light (Light.color).

Fantastic! Thanks for your reply I’ll look into these and see where it leads me. There’s one thing I don’t get at the moment though, what’s the fraction between paddles calculation for?