I am making a mobile game in Unity, and I want to make some text fade out. I have created a for loop that increases the alpha value of the text's color by one 255 times. When I run the code, it gives me a NullReferenceException, saying "Object reference not set to an instance of an object". Here is the for loop causing the problem.
{
for(int alphaVal = 0; alphaVal < 256; alphaVal++)
{
text.color = new Color(red, green, blue, alphaVal);
}
}