Dynamically creating GUITexture's ?

Hello

I need to create (and destory) GUITexture’s and move them around the screen.

right now im trying something like new GUITexture and adding a Texture2D to GUITexture.texture , and it seems to compile, but i cannot see anything on the screen.

I couldnt find any way to go about this, all i could find is using Instantiate to clone an existing prefab, which doubles the amount of assets i have in my roject folder (1 texture and 1 guitexture), especially when the texture’s are going to be destroyed once they get to the other end of the screen.

How should I go about this?

This should work. Maybe you’re putting it somewhere that isn’t visible on the screen. GameObjects with GUIElements have to be positioned in world space relative to the world origin such that (0, 0, 0) is the middle of the screen, (1, 1, 0) is the top right corner and (-1, -1, 0) is the bottom left corner.

A common mistake is to make the GUIElements children of a freely moving object such as the main camera. Since their positions in world space are used to determine their positions onscreen, the parent object’s movement is likely to take them offscreen straight away.

Also, check that one of your cameras has a GUILayer component or none of your GUIElements will be visible no matter how you create them!

You must not use “new GUITexture”…but create a GameObject and add GUITexture component.
Like this:

var go:GameObject = new GameObject("test");
var guiTex:GUITexture = go.AddComponent(GUITexture);