renderer.color.a +=

I’m having a problem with this:

	if(anotherScript.isHurt == true)
		{

			Color color = renderer.material.color;
			color.a += 0.01f;

		
		}else

		{

			Color color = renderer.material.color;
			color.a -= 0.01f;
		
		}

Instead of slowly fading the screen black and out it doesnt do anything.
I’ve attached a plane on the screen:

var bloodObject = GameObject.Find("bloodObject");

	if(bloodObject)
		{

			bloodRenderer = bloodObject.renderer;

			bloodRenderer.material.color = new Color(0.0f, 0.0f, 0.0f, 0.0f);
		}
		else
		{
			Debug.LogWarning("Not found");
		}

Im using Transparent VertexLit

1 Answer

1

You need to reassign the color to the material.

 Color color = renderer.material.color;
 color.a += 0.01f;
 renderer.material.color = color;