- Home /
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:
I do not know how to make the texture to flicker (E.g. change alpha just for 4 seconds)
It is not drawing my texture as red (its staying white as in the original texture)
I cannot find a way to resize properly to 5 x 5
Any help would be appreciated!
Answer by karljj1 · Dec 10, 2013 at 03:51 PM
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. http://docs.unity3d.com/Documentation/ScriptReference/GUI.DrawTexture.html
Answer by robhuhn · Dec 10, 2013 at 04:17 PM
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);
Your answer
![](https://koobas.hobune.stream/wayback/20220613123846im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UnityEditor - Drawing on a Texture 1 Answer
ReadPixels requires an offset while in the Editor? 2 Answers
How can I save the Bild from a Camera, which not main camera is. 1 Answer
Detect WWW Image bitmap dimensions? 2 Answers
Get RenderTexture 1 Answer