- Home /
How to make a custom GUITexture at runtime?
I want to make a simple app which has a GUITexture in the middle of the screen, the GUITexture has a Texture2D texture, which is a blue rectangle made somehow with SetPixels().. Im really new to Unity, and i cant make it work.. How to do this? And if im wrong, and it cant be made this way, then how to make a gui element which pixels can be modified at runtime?
@Novodantis: it doesn't matter. Free/Pro has no difference in functionality in this case.
Answer by Eric5h5 · Apr 18, 2010 at 12:40 AM
Make a Color array filled with blue and assign that to a texture using SetPixels. Then assign that texture to the texture property of the GUITexture object.
Answer by yoyo · Oct 19, 2010 at 04:47 PM
Thanks Eric5h5, that answers my question too. Here's the code (C#) ...
GameObject obj = new GameObject("SolidColour");
obj.AddComponent("GUITexture");
obj.transform.localScale = Vector3.zero;
obj.guiTexture.pixelInset = new Rect(0,0,40, 20);
Texture2D tex2d = new Texture2D(1, 1);
tex2d.SetPixels(new Color[1] { Color.red });
tex2d.Apply();
obj.guiTexture.texture = tex2d;
Your answer
Follow this Question
Related Questions
Setting pixels on a texture? 2 Answers
Transparent overlay on Mesh 0 Answers
Draw one texture on to another? Get Set Pixels. 0 Answers
Merging Textures At Runtime - Not Correct? 1 Answer
Best way to show an image 2 Answers