x


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?

more ▼

asked Apr 17 '10 at 11:22 PM

Richard Fulop gravatar image

Richard Fulop
28 2 2 3

Is this the free version of Unity, or Unity Pro?

Apr 17 '10 at 11:50 PM Novodantis 1

@Novodantis: it doesn't matter. Free/Pro has no difference in functionality in this case.

Apr 18 '10 at 12:39 AM Eric5h5
(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

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.

more ▼

answered Apr 18 '10 at 12:40 AM

Eric5h5 gravatar image

Eric5h5
80.3k 42 132 521

(comments are locked)
10|3000 characters needed characters left

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;
more ▼

answered Oct 19 '10 at 04:47 PM

yoyo gravatar image

yoyo
6.4k 25 39 84

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x2200
x475
x354
x37

asked: Apr 17 '10 at 11:22 PM

Seen: 5110 times

Last Updated: Apr 17 '10 at 11:22 PM