Dimling
1
Hello!
I’m in a bit of a hurry. Got the idea of making an advent calendar yesterday in the new Unity2D devolping, and its going pretty good. But having a problem with the GUI-texture. When the main player is walking on a hatch it is possible to open it (based on the date), and a GUI-texture are going to pop up in the middel of the screen while pressing the key O. It will then retrive the right gui texture from the right hatch to the GUI-texture object and display it. As you can see in the picture attached, it gets the picture and enables it as visible, but it won’t show up on the screen???

The original state of the object is GUITexture disabled and Texture = None.
using UnityEngine;
using System.Collections;
public class ContentGuiHandler : MonoBehaviour {
public static bool isVisible = false;
public static Texture2D textureContent = null;
// Update is called once per frame
void Update () {
if(isVisible == true){
this.gameObject.guiTexture.texture = textureContent;
this.gameObject.guiTexture.enabled = true;
}
else{
this.gameObject.guiTexture.enabled = false;
}
}
}
This is the code in the player object that set the GUI-texture…(rest of the code is omitted)
if(showingContent == false && onAHatch == true && Input.GetKeyDown(KeyCode.O)){
showingContent = true;
ContentGuiHandler.textureContent = contentToBeShown;
ContentGuiHandler.isVisible = true;
}
if(Input.GetKeyUp(KeyCode.O) && showingContent == true){
showingContent = false;
//ContentGuiHandler.textureContent = null;
ContentGuiHandler.isVisible = false;
}
If I pull the texture on the Inspector, while the game is not playing, the GUI-texture is working, and of course if I play the game then it works. But not when i try to enables it trough the code. Hope anyone knows, in a hurry and have never experienced this problem before. I do the same thing with infoboxes. If the player hits the hatch-trigger it will show a infobox that says “Press O to open hatch”, and this is working fine. What the fudge am i doing wrong?
Thanks btw 
Dimling
2
The problem sovled itself. Hurray!!! Now idea way. Deleted the GuiTexture object a few times and added the script on to the object again, suddenly it worked. No idea way. But I don’t delete this message if anyone have clue why this happend. I’m intressted to know! 