- Home /
How to make minimap GUI stay put?
I am using C# scipt to use render texture and material. When I switch from 16:9 screen ratio to full screen on play, the GUI is in another location. How can I make it stay?
Would it be in the right place if I built the game in 16:9 and resized my screen?
Thank you!
note: even when dragging the screen to enlarge the scene view, the GUI gets out of place, while being in 16:9 the entire time.
Here is my script for minimap:
using UnityEngine;
public class minimapcee : MonoBehaviour {
public RenderTexture MiniMapTexture;
public Material MiniMapMaterial;
private float offset;
void Awake()
{
offset = 10;
}
void OnGUI()
{
if(Event.current.type == EventType.Repaint)
Graphics.DrawTexture(new Rect(14, 278, 88, 88), MiniMapTexture, MiniMapMaterial);
}
}
Answer by purplelilgirl · Sep 05, 2012 at 03:45 AM
Try using this script:
Graphics.DrawTexture(new Rect(14, 278, 88, 88), MiniMapTexture, MiniMapMaterial);public float screenWidth = 960; public float screenHeight = 640; Matrix4x4 tMatrix; void Awake () { RotateDevice(); } void RotateDevice() { tMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, new Vector3((float)1.0 Screen.width/screenWidth, (float) 1.0 Screen.height/screenHeight, 1.0f)); } void OnGUI() { GUI.matrix = tMatrix; if(Event.current.type == EventType.Repaint)
}
Set screenWidth and screenHeight to your 16:9 one, and the rest of the script will automatically resize and reposition your GUI based on the current screen size, so that it will always be in the "right" place.
omg, I don't know why it won't format correctly >.<
poo, I'm gettin errors with this code, is it meant to replace the code or only part? New to scripting :(
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Is there something wrong with my c# script? 1 Answer
Leaderboard GUISkin? 1 Answer
Highscore GUI not working properly help 0 Answers
Using GUI skin with my GUI Button 1 Answer