- Home /
Screen pos out of view frustrum, Minimap Cleanup
I made a Minimap, or "Radar" that shows the entire world in my game.
This map can change size depending on what you use for the camSize variable in game. set it to 0 makes the frustrum error appear. Another thing my camera does is that it errors if i dont enter a value for camSize, so if camSize is empty i force the digit 1 to be my camSize, however for a brief second i get another error.
I understand why. My question is, is my scripting ok or should i do something different? Im not an advanced coder so i dont know if i should ignore the errors or find a work around.
If anyone wants to see the code:
using UnityEngine;
using System.Collections;
using System.Text.RegularExpressions;
public class Maps : MonoBehaviour {
public Camera worldMap;
public bool mapOpen = false;
private string camSize = "1000";
public GUISkin customSkin;
void Start () {
mapOpen = false;
}
void Update(){
if(Input.GetKeyUp (KeyCode.M)){
mapOpen = !mapOpen;
}
}
void OnGUI(){
GUI.skin = customSkin;
if(camSize == "" || camSize == "."){
camSize = "1";
}
if(mapOpen){
GUI.Label(new Rect(Screen.width / 2 - 10, Screen.height / 2 - 10, 20, 20),"▲");
worldMap.rect = new Rect (0, 0, 1, 1);
camSize = GUI.TextField (new Rect(Screen.width - 50, Screen.height - 20, 50, 20), camSize);
camSize = Regex.Replace(camSize, @"[^0-9.]", "");
float temp = float.Parse(camSize);
worldMap.orthographicSize = temp;
}
if(!mapOpen){
worldMap.rect = new Rect (0, 0, 0, 0);
}
}
}
Answer by Bunny83 · Mar 23, 2014 at 11:46 PM
Instead of line 29 and 30 you should do something like this:
float temp;
if (float.TryParse(camSize, out temp))
{
worldMap.orthographicSize = temp;
}
edit
In addition you could / should wrap the whole part with an "GUI.changed"-if like this:
camSize = GUI.TextField (new Rect(Screen.width - 50, Screen.height - 20, 50, 20), camSize);
if (GUI.changed)
{
camSize = Regex.Replace(camSize, @"[^0-9.]", "");
float temp;
if (float.TryParse(camSize, out temp))
{
worldMap.orthographicSize = temp;
}
}
This avoids unnecessary parsing (which would otherwise happen 2 times each frame) and setting of the orthographicSize (which will probably cause the camera's internal matrix to be recalculated).
ps: Do you need to have an input field for the size? Usually it's more convenient to display a slider
I do not, ill probably convert to sliders because it seems odd to use a text field now that you have mentioned it. Thanks for your input. Ill try doing what you said.
Your answer
![](https://koobas.hobune.stream/wayback/20220613141014im_/https://answers.unity.com/themes/thub/images/avi.jpg)