Hi all,
I do this:
public Texture2D tex;
void OnGUI ()
{
GUI.DrawTexture (new Rect (0,50,100,50), tex);
}
And can assign the texture in the inspector - but can’t see how I do it dynamically i.e. in the script.
Also (I am, still learning) suppose this texture I wanted to act as an icon would I ‘somehow’ spawn an empty game object and dynamically apply a script to it and have that be an instance of my icon?
i.e. is that the best/correct approach ; if so some demo code would help.
thanks in advance
Here is an example of a button the has a 2DTexture loaded dynamically when the user drag the button. The tCube is a texture2D that I load the moment the user drags, you can ignore the ithe stuff, it is just to show you.
if (GUI.Button(new Rect(5, 0, 50, 50), tCube))
{
objToCreate = cube;
objType = "cube";
dragIcon = tCube;
isDraggingNewObject = true;
}
let us know if you need more help
Hi chubbspet,
Sorry I’m confused (it ain’t difficult for that too happen
)
Your example is using the built in unity/gui button stuff right?
If so, how do I just draw a texture i.e. not a selectable button?, also please explain what types objtocreate,objtype,tCube etc. are?
thanks for your response.
Hmmm,
Ok, well:
var myTexture = Resources.Load(“myImage”);
Apparently does it. But if I want to animate my texture (i.e. use different textures per frame) is this the only route?
Seems rather cumbersome; I guess that’s why the asset store has 2d guy texture handlers (and of course the benefit of texture atlas)
Hmmmmmm
Cheers
If you want to animate a texture, my guess will be that it would be better to store the images in an array of typoe Texture2D. Obviously performance will be an issue here, that is why I say an array rather than every time loading using resources.Load. What is it exactly that you want to achieve at the end of the day?
Thanks
Well, I’m trying to make an efficient way of spawning/managing and animating GUI elements.
I realise though (as many have said) that this is the point at which Unity doesn’t fare so well :-((
Cheers