Hi,
I’m a new developer on Unity myself (only a 1 month old Unity) and this is my first post. Hope to be here often with time.
So for my question - I am developing a GUI system that will have many elements that will be revealed and hidden dynamically, as the screens of the game are displayed and hidden.
For instance, an exotic and wide looking button, will be smoothly shown as if a transparent to view yet obscuring rectangle is removed from on top of it.
This means that the game background behind this action should be displayed but the GUI element will be hidden until revelation.
I am currently trying to work with Texture2D.
I’m loading a TextAsset png (with .txt extension) and trying to copy the section I want from it to the Texture2D I am showing on screen and then giving this Texture2D as an argument to a GUILabel.
My questions are:
- What do you think of this solution? sound kind of too expensive for what I wanna do. Do you know or think of any other way to achieve what I want?
- I can’t seem to see the image on screen - I use GetPixels from the source image and SetPixels on the target image, but all I get is a question mark.
I’ll try to point out the big issue in my question:
public TextAsset imageAsset;
public Texture2D originalTexture;
public Rect area;
void start()
{
originalTexture = new Texture2D((int)area.width, (int)area.height, TextureFormat.ARGB32, false);
originalTexture.LoadImage(imageAsset.bytes);
// originalTexture.Apply();
}
void OnGUI()
{
GUI.Label(area, originalTexture);
}
Given this code snippet,
what could make the label display a question mark?
(note: the whole code looks different. I’ve narrowed the issue to these lines. Eventually, I wanna copy the original texture into a target texture (specific parts of it) )
I’m not 100% sure you can just use textures there.
Labels expect strings to draw.
The GUIContent block is normally used to encapsulate textures for usage in such cases.
Hmm…
According to the help section:
static function Label (position : Rect, image : Texture, style : GUIStyle) : void
Is a valid function. Also, I should have got a compile error if a Texture wasn’t a valid argument.
You are right.
Then the loading of the texture potentially failed.
You can easily test it by removing the whole load part in start and just assigning the originalTexture in the editor (just drag the image in your project onto it)
Thanks, but that’s how I placed the texture in the first place.
I just went for a different approach all together.
What I am wondering now though, is if I could actually setpixels in the update() function, since calling Apply() each update is very slow.
Have any idea?
This may seem obvious, but don’t you need to decode a png image from the bytes in the text file?