Trouble changing sprite material alpha.

I’ve got a sprite parented to my Main Camera with a slight Z offset to the front to act as a blind for fading between levels. Tried to change the material colour’s alpha value from 0 to 1.0 on click but that doesn’t work. Debug.Log recognizes the mouse-clicks.

The sprite:

[21050-screen+shot+2014-01-24+at+3.32.34+am.png|21050]

The material:

[21051-screen+shot+2014-01-24+at+3.35.47+am.png|21051]

My script:

Color tempColor;

	void Start ()
	{
		tempColor = renderer.material.color;
	}

	void Update ()
	{
		if (Input.GetMouseButtonDown (0))
			tempColor.a = 1.0f;
	}

Edit: Solved with a GUITexture with the following settings:

  • Position .5, .5,
  • Scale 1, 1
  • Texture field has 1x1px image (wouldn’t render without)
  • Pixel Inset zeroed out.

In the script, declare a temporary Color variable to guiTexture.color, assign an alpha value, and remember to assign the Color variable you declared back to guiTexture.color.

Color guicolor = guiTexture.color;

		guicolor.a = 0.0f;

		guiTexture.color = guicolor;

You’re not changing the color of the material, you’re just making a copy of the material’s color and changing that, which will have no effect on the material.