Texture2D to GUITexture?

Hi guys,

I was just wondering if there is a way of assigning the result of a generated texture that is stored in a Texture2D type variable to a GUITexture.texture to have it actually display on screen.

Directly assigning it as this:

01 mapTexture = menuObj.GetComponent( GUITexture );
02		mapTexture.texture.SetPixels(structureGen.mapTexture.GetPixels());
03		mapTexture.texture.Apply();

where structureGen.mapTexture is the stored image in a Texture2D format, works in Editor.
It does not Build though (the project is set to iOS), because of the following errors:

the errors on these three lines of code when turning on #pragma strict

01 Cannot convert ‘UnityEngine.Component’ to ‘UnityEngine.GUITexture’.
02 ‘SetPixels’ is not a member of ‘UnityEngine.Texture’.
03 ‘Apply’ is not a member of ‘UnityEngine.Texture’.

I understand this as of course, mapTexture.texture is not a Texture2D to which those methods apply.

My question is, how would you guys assign the texture2D content to a GUITexture.texture

Thank you in advance for any answers.

Bye the way, Happy Holidays to all! (i do not wish to break a chain of programming nights :slight_smile:

are you sure it’s not something simple like?
menuObj.getComponent(GUITexture).texture = mapTexture

Hi callahan.44

Yes that is what i first tried to use, but actually, as i remember did not work for me.

But now I have it figured out. I used a buffer texture that is also of Texture2D type,
and I do not make other operations on it (like the SetPixels and Apply)…
I make the operations on the buffer texture, which is then only assigned to the GUITexture.texture.

That works :slight_smile:

var mapTexture : GUITexture;
var mapTextureBuffer : Texture2D;

mapTexture = menuObj.GetComponent( GUITexture );
		
		mapTextureBuffer.SetPixels(structureGen.mapTexture.GetPixels());
		mapTextureBuffer.Apply();
		mapTexture.texture = mapTextureBuffer;

Thank you again for your answer, Your effort is greatly appreciated.