- Home /
GUI.Label question about Resolution
Hello everyone, I simply want to place texts on the screen so I use GUI.Label like this:
GUI.Label (Rect(Screen.width - 200,Screen.height-500,200,80),"Points : ");
I can adjust it very well according to my resolution ( 1920x1080 ) but when I run the game in 1024x768 for example, texts' places will be messed up, even some of them gets out of the screen & become invisible. Is there any way to make the text occur always on the same place of the screen without changing according to the resolution ? Thanks :)
Answer by Berenger · Jun 12, 2012 at 04:36 PM
You seems to be coding in unityscript, so put that script in a Standard Assets folder (I didn't test it) :
using UnityEngine;
[System.Serializable]
public class ViewportRect
{
private float m_fX = 0f, m_fY = 0f, m_fWidth = 1f, m_fHeight = 1f;
public float x{ get{ return m_fX; } set{ m_fX = Mathf.Clamp01(value); } }
public float y{ get{ return m_fY; } set{ m_fY = Mathf.Clamp01(value); } }
public float width{ get{ return m_fWidth; } set{ m_fWidth = Mathf.Clamp01(value); } }
public float height{ get{ return m_fHeight; } set{ m_fHeight = Mathf.Clamp01(value); } }
public ViewportRect():this(0f,0f,1f,1f){}
public ViewportRect( Rect r ){ FromRect(r); }
public ViewportRect( float _x, float _y, float_width, float _height )
{
x = _x;
y = _y;
width = _width;
height = _height;
}
public Rect ToRect()
{
return new Rect( x * Screen.width, y * Screen.height, width * Screen.width, height * Screen.height );
}
public ViewportRect FromRect( Rect r )
{
x = r.x / Screen.width;
y = r.y / Screen.height;
width = r.width / Screen.width;
height = r.height / Screen.height;
return this;
}
}
The point is to manipulate coordinate between 0 and 1. Be carefull, the ratio will be lost.
Your answer
Follow this Question
Related Questions
Changing a GUILabel text SIZE 3 Answers
How to input a current resolution on GuiText? 1 Answer
GUI Label Size and Position Changes With Resolution 2 Answers
Relate font size to screen size in GUISkin 2 Answers
Color.white not so much white... 3 Answers