- Home /
Why displayed wrong texture?
I synthesize a texture using "new Texture2D" and "SetPixel". I assign this to a "GUITexture.texture". Why is this displayed as if all pixels were transparent gray? PNG textures are displayed correctly.
Example of synthesized texture (Tx) on a GUITexture instance.
Texture2D Tx = new Texture2D(128,128,TextureFormat.ARGB32) ;
for( int i=0 ; i<Tx.width ; i++ )
for( int j=0 ; j<Tx.heigth ; j++ )
Tx.SetPixel(i,j,new Color(0f,0.5f,1f,1f)) ;
GameObject.Find("Blue Square").GetComponent<GUITexture>().texture = Tx ;
Comment
Best Answer
Answer by zharik86 · Nov 09, 2014 at 07:58 AM
You forgot apply your texture in memory. See code:
Texture2D Tx = new Texture2D(128,128,TextureFormat.ARGB32);
for(int i = 0; i < Tx.width; i++)
for(int j = 0 ; j < Tx.heigth; j++)
Tx.SetPixel(i,j,new Color(0f,0.5f,1f,1f));
Tx.Apply(); //apply your texture
GameObject.Find("Blue Square").GetComponent<GUITexture>().texture = Tx;
I hope that it will help you.
Your answer
![](https://koobas.hobune.stream/wayback/20220613171052im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Best way to show an image 2 Answers
I need to add a hyperlink to a string that appears on a GUI texture. 1 Answer
How to make a custom GUITexture at runtime? 2 Answers
Can't Resources.load new generated texture2D as lightmaps at run time 0 Answers
how can i show number of lives as hearts (or other image) during gameplay 4 Answers