Hi,
I have a problem with my Minimap that I created few months ago with that tutorial. I edited it two days ago with a little script that zoom it out and in. For some reason when I build my game, the minimap doesn’t render…
EDIT: I realised that a mini HUD that I have in my inventory doesn’t render… So I change the title to Graphics.
The code I use:
//Options menu, the menu options is there:
private static float _minimapZoom;
public static float MinimapZoom {
get {return _minimapZoom;}
set {_minimapZoom = value;}
}
void OnGUI() {
if(Minimap) {
if (style != "menu") {
GUI.DrawTexture(new Rect(Screen.width/2-350, Screen.height/2-252, 700, 525), preTab);
}
string MinimapStr = "";
if(MinimapZoom >= 30 && MinimapZoom < 100) {
MinimapStr = "x16";
} else if(MinimapZoom >= 100 && MinimapZoom < 200) {
MinimapStr = "x8";
} else if(MinimapZoom >= 200 && MinimapZoom < 400) {
MinimapStr = "x4";
} else if(MinimapZoom >= 400 && MinimapZoom < 600) {
MinimapStr = "x2";
} else if(MinimapZoom >= 600 && MinimapZoom < 800) {
MinimapStr = "x1";
} else if(MinimapZoom >= 800) {
MinimapStr = "x0.5";
}
GUI.Label(new Rect(MarginW-300, MarginH-287+50, 300, 30), "Zoom del Minimapa: " + MinimapStr);
MinimapZoom = GUI.HorizontalSlider(new Rect(MarginW-300, MarginH-287+75, 300, 20), MinimapZoom, 30, 1000);
if(GUI.Button(new Rect(MarginW-100, MarginH-287+75+515-95, 200, 50), "Hecho")) {
ApplyChanges();
Minimap = false;
MenuStart = true;
}
}
}
Apply changes:
private static void ApplyChanges() {
//Var != 0 is for avoid bugs
if (FOV != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "FOV", Convert.ToString (FOV));
}
if (Sensibility != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "Sensibility", Convert.ToString (Sensibility));
}
if(Brightness != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "Brightness", Convert.ToString(Brightness));
}
if(RenderDistance != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "RenderDistance", Convert.ToString(RenderDistance));
}
if (MaxFPS != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "MaxFPS", Convert.ToString (MaxFPS));
} else if (MaxFPS < 10) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "MaxFPS", "-1");
}
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "InvertMouse", Convert.ToString(Convert.ToInt32(InvertMouse)));
if (MinimapZoom != 0) {
INI_Manager.Set_Value (Application.dataPath + "/appConfig.cfg", "MinimapZoom", Convert.ToString (MinimapZoom));
}
ReadValues();
}
Read all the values again:
private static void ReadValues() {
GameGUI.GUIOptions.SetSensivity (InvertMouse, Sensibility);
Camara.fieldOfView = FOV;
Camara.farClipPlane = RenderDistance;
RenderSettings.ambientLight = new Color(Brightness, Brightness, Brightness, 1.0f);
}
The function that set the camera position
//The player system class
public static void MiniMap(GameObject player, float seg) {
Camera.minimap.transform.position = new Vector3(player.transform.position.x, player.transform.position.y + seg, player.transform.position.z);
}
Player script attached to the scene:
public class PlayerSystemindex : MonoBehaviour {
...
GameObject player = ....
void Update() {
PlayerSystem.MiniMap(player, Options.MinimapZoom);
}
}
Rendering on GUI:
//And render it on the GUI... (As the tutorial said)
void OnGUI() {
if(Event.current.type == EventType.Repaint) {
Graphics.DrawTexture (new Rect (Screen.width - 215, 61, 150, 150), minimapTexture, minimapMaterial);
}
}
Builded game:
Editor game:
And a few images of how I set everything…
PD: I don’t have any script on it. And I test to change everything on the cam, and in the script (like setting manual y-coords, displayig the game in full screen and in windows version, etc)
What can be wrong??
Sometimes when I change the VSync the map dissapear (on Editor too), because I have a class that was changed and I put it at the start of anything that loads everything:
using UnityEngine;
using System.Collections;
public class MainThread : MonoBehaviour {
void Awake() {
//Set all the values at start
Options.SetValues();
QualitySettings.vSyncCount = Options.VSync;
Application.targetFrameRate = (int)Options.MaxFPS;
}
}
Set values:
public static void SetValues() {
preTab = (Texture2D)Resources.Load ("images/preTab2");
FOV = float.Parse(INI_Manager.Load_Value(Application.dataPath + "/appConfig.cfg", "FOV"));
Sensibility = float.Parse(INI_Manager.Load_Value(Application.dataPath + "/appConfig.cfg", "Sensibility"));
RenderDistance = float.Parse(INI_Manager.Load_Value(Application.dataPath + "/appConfig.cfg", "RenderDistance"));
MaxFPS = float.Parse(INI_Manager.Load_Value(Application.dataPath + "/appConfig.cfg", "MaxFPS"));
VSync = Convert.ToInt32(INI_Manager.Load_Value (Application.dataPath + "/appConfig.cfg", "VSync"));
InvertMouse = Convert.ToBoolean(Convert.ToInt32(INI_Manager.Load_Value(Application.dataPath + "/appConfig.cfg", "InvertMouse")));
Brightness = float.Parse(INI_Manager.Load_Value (Application.dataPath + "/appConfig.cfg", "Brightness"));
MinimapZoom = float.Parse(INI_Manager.Load_Value (Application.dataPath + "/appConfig.cfg", "MinimapZoom"));
//That is for set default values if the app is bugged
if (FOV == 0 || FOV == null) {
FOV = 60;
}
if (Sensibility == 0 || Sensibility == null) {
Sensibility = 15;
}
if (RenderDistance == 0 || RenderDistance == null) {
RenderDistance = 1000;
}
if (MaxFPS == 0 || MaxFPS == null) {
Brightness = 0.3f;
}
if (VSync == null || VSync == null) {
VSync = 1;
}
if (InvertMouse == null) {
InvertMouse = false;
}
if (MinimapZoom == 0 || MinimapZoom == null) {
MinimapZoom = 100;
}
ReadValues();
}
It can be too the Event?
I don’t use any plaform dependant compilation on this part of the code. (I use it in other parts)
Maybe, its a Bug?? GUI.DrawTexture shows in Unity but not in Build - Unity Answers
Thanks in advance.
Bye.