GuiRatioFixer

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
Line 5: Line 5:
  
 
  using UnityEngine;
 
  using UnityEngine;
using System.Collections;
+
using System.Collections;
 
+
// Use this on a guiText or guiTexture object to automatically have them
+
// Use this on a guiText or guiTexture object to automatically have them
// adjust their aspect ratio when the game starts.
+
// adjust their aspect ratio when the game starts.
 
+
public class GuiRatioFixer : MonoBehaviour
+
public class GuiRatioFixer : MonoBehaviour
{
+
{
public float m_NativeRatio = 1.3333333333333F;
+
public float m_NativeRatio = 1.3333333333333F;
+
void Start ()
+
void Start ()
{
+
{
float currentRatio = (float)Screen.width / (float)Screen.height;
+
float currentRatio = (float)Screen.width / (float)Screen.height;
Vector3 scale = transform.localScale;
+
Vector3 scale = transform.localScale;
scale.x *= m_NativeRatio / currentRatio;
+
scale.x *= m_NativeRatio / currentRatio;
transform.localScale = scale;
+
transform.localScale = scale;
}
+
}
+
}
+
}

Revision as of 01:55, 1 December 2005

Author: Jon (Aarku)


Use this on a guiText or guiTexture object to automatically have them adjust their aspect ratio when the game starts.


using UnityEngine;
using System.Collections;

// Use this on a guiText or guiTexture object to automatically have them
// adjust their aspect ratio when the game starts.

public class GuiRatioFixer : MonoBehaviour
{
	public float m_NativeRatio = 1.3333333333333F;
	
	void Start ()
	{
		float currentRatio = (float)Screen.width / (float)Screen.height;
		Vector3 scale = transform.localScale;
		scale.x *= m_NativeRatio / currentRatio;
		transform.localScale = scale;
	}
	
}
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox