Hey there forum,
I have kind of a special problem. A GUI Box that I draw does not go away when I want it to. I have modeled a building and have a orthographic camera on top of it to use as a map. The camera has a higher depth so that it can be shown over the first person camera. The camera takes 0.2*0.2 of the screen size to use it as a minimap. By pressing “M”, the camera is enlarged to fullscreen, and buttons appear ( they are invisible) over the rooms, so that you can click on a room and get information concerning the room. A Box is drawn on the top left, where the information are shown. When you open the map, the infobox tells you to click on a room. Which room is clicked, is stored in a int variable. If there is no room clicked, the info box telling you to click on a room is shown, if a room is clicked, the info box shows information about the room. This is the code in C#:
using UnityEngine;
using System.Collections;
using System;
using System.Collections.Generic;
public class MapController : MonoBehaviour {
private bool mapShown;
private int roomClicked;
private List<Rect> buttonPos = new List<Rect>();
public bool debug;
public Camera mapcam;
public string[] roomDescriptions;
// Use this for initialization
void Start () {
mapcam=GameObject.FindGameObjectWithTag("Mapcam").camera;
//define button positions
Rect info = new Rect(10,10,Screen.width*.4f,Screen.height*.2f);
Rect room1 = new Rect(Screen.width*.297f,Screen.height*.621f,Screen.width*.214f,Screen.height*.308f);
Rect room2 = new Rect(Screen.width*.54f,Screen.height*.044f,Screen.width*.22f,Screen.height*.244f);
Rect room3 = new Rect(0,0,0,0);
Rect room4 = new Rect(0,0,0,0);
Rect room5 = new Rect(0,0,0,0);
Rect room6 = new Rect(Screen.width*.517f,Screen.height*.621f,Screen.width*.242f,Screen.height*.308f);
Rect room7 = new Rect(0,0,0,0);
Rect room8 = new Rect(Screen.width*.425f,Screen.height*.044f,Screen.width*.11f,Screen.height*.244f);
Rect room9a = new Rect(Screen.width*.431f,Screen.height*.288f,Screen.width*.334f,Screen.height*.323f);
Rect room9b = new Rect(Screen.width*.765f,Screen.height*.044f,Screen.width*.093f,Screen.height*.885f);
Rect room10 = new Rect(Screen.width*.066f,Screen.height*.621f,Screen.width*.224f,Screen.height*.227f);
buttonPos.Add(info);
buttonPos.Add(room1);
buttonPos.Add(room2);
buttonPos.Add(room3);
buttonPos.Add(room4);
buttonPos.Add(room5);
buttonPos.Add(room6);
buttonPos.Add(room7);
buttonPos.Add(room8);
buttonPos.Add(room9a);
buttonPos.Add(room10);
buttonPos.Add(room9b);
}
// Update is called once per frame
void Update () {
//Big Map
if (Input.GetKeyDown(KeyCode.M)){
if (!mapShown){
mapcam.pixelRect = new Rect(0,0,Screen.width,Screen.height);
mapShown=true;
} else {
mapcam.pixelRect = new Rect(Screen.width*0.8f,Screen.height*0.8f,Screen.width*0.2f,Screen.height*0.2f);
mapShown=false;
roomClicked=0;
}
}
}
void OnGUI(){
if(!mapShown){
//Minimap Border
Texture2D MyTexture = Resources.Load("white") as Texture2D;
GUI.color = new Color(0f , 0f, 0f);//Set color to red
int border = 5;
//vertical border
GUI.DrawTexture(new Rect(Screen.width*0.8f-border, 0, border, Screen.height*0.2f+border), MyTexture);
//horizontal border
GUI.DrawTexture(new Rect(Screen.width*0.8f, Screen.height*0.2f, Screen.width*0.2f+border, border), MyTexture);
GUI.color = Color.white;//Reset color to white
} else {
//clickable rooms (buttons)
for (int i = 1; i < roomDescriptions.Length; i++) {
if (GUI.Button(buttonPos[i],"", GUIStyle.none))
roomClicked=i;
}
//Room 9b is the corner of room9
if (GUI.Button(buttonPos[11],"", GUIStyle.none)){
roomClicked=9;
}
GUI.Box(buttonPos[0],roomDescriptions[roomClicked]);
}
}
}
Now the problem is, that the first infobox does not disappear and also that it is solid instead of transparent. It looks like this:
But it should look like this:
This problem only appears, when the first box is drawn directly with the fullscreen map. When I don’t draw the fist box, everything is fine and the info for the rooms changes smoothly when clicking on different rooms. I tried setting a variable “start” to Time.time when pressing “M” and drawing the first box after Time.time>start. This also makes the box solid and it does not disappear.
I hope anyone can help me, thanks for reading.