Firstly, I’ll let you know that this script is currently functioning correctly - that is, the ballMaterial’s alpha value fades to 0.3 while the camera is within a certain distance of the ballObject. My issue is that without the “ballColor.r”, “ballColor.g” and “ballColor.b” lines in place, the RGB colour of the ballObject’s material changes to (0,0,0) and stays there throughout play and even after play mode has been stopped. I simply don’t understand how the RGB is getting changed to black when I only have a line modifying the alpha channel! At the very least I’d expect the RGB to fade between black and white with the alpha, but no…
If I’m doing something slightly wrong, it would be handy to know - and if this is just the way it works, is there a more elegant way of overriding the RGB? The multi-line solution I have at the moment seems really clumsy!
void FixedUpdate()
{
if (Vector3.Distance(ballCamera.position, ballObject.position) < fadeDistance)
{
FadeBall(0.3f);
}
else
{
FadeBall(1.0f);
}
}
void FadeBall(float targetOpacity)
{
ballColor.a = Mathf.Lerp(ballColor.a, targetOpacity, /*Time.time **/ fadeDamping);
ballColor.r = 1;
ballColor.g = 1;
ballColor.b = 1;
ballMaterial.color = ballColor;
}