Make a texture flicker c#

Hi
I have a texture that I am instantiating:

Texture2D starTexture = Instantiate(tex) as Texture2D;

I am then drawing this texture onto the screen:

Graphics.DrawTexture(new Rect(0, 0, 5, 5), starTexture, new Rect(0,0, starTexture.width, starTexture.height), 0, 0, 0, 0, Color.red);

My problems are the following:

  1. I do not know how to make the texture to flicker (E.g. change alpha just for 4 seconds)
  2. It is not drawing my texture as red (its staying white as in the original texture)
  3. I cannot find a way to resize properly to 5 x 5

Any help would be appreciated!

1)Try iTween for the flicker. iTween.ColorTo
http://itween.pixelplacement.com/documentation.php

2)Where do you want the texture to be? If its in the GUI then use GUI.DrawTexture or GUI.Label instead of Graphics. If its in the scene then put it on a mesh and make the shader transparent.

3)If you use GUI.DrawTextureyou can set the size in the the Rect.

  1. You could use Invoke to set a flag after a delay or set an interval timer e.g.

    void Start ()
    {
    Invoke(“ToggleDrawTex”, 4f);
    }

    bool drawTex = true;
    void ToggleDrawTex()
    {
    drawTex = !drawTex;
    Invoke(“ToggleDrawTex”, 4f);
    }

    void OnGUI()
    {
    if(drawTex)
    {
    Graphics.DrawTexture(new Rect(0, 0, tex.width, tex.height), tex, new Rect(0, 0, 1, 1), 0, 0, 0, 0, Color.red);
    }
    }

  2. Don’t know - Works for me

  3. Try:

    Graphics.DrawTexture(new Rect(0, 0, 5, 5), starTexture, new Rect(0,0, 1, 1), 0, 0, 0, 0, Color.red);

or if 5x5 is the original size:

Graphics.DrawTexture(new Rect(0, 0, starTexture.width, starTexture.height), starTexture, new Rect(0,0, 1, 1), 0, 0, 0, 0, Color.red);