GuiRatioFixer

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

Revision as of 06:45, 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.

C#

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;
	}
	
}

Boo

import UnityEngine;
import System.Collections;

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

class GuiRatioFixer (MonoBehaviour):

	public m_NativeRatio = 1.3333333333333
	
	Start ():
		currentRatio = (Screen.width+0.0) / Screen.height
		scale = transform.localScale
		scale.x *= m_NativeRatio / currentRatio
		transform.localScale = scale

Javascript

// Use this on a guiText or guiTexture object to automatically have them
// adjust their aspect ratio when the game starts.
var m_NativeRatio = 1.3333333333333;
	
currentRatio = (Screen.width+0.0) / Screen.height;
transform.localScale.x *= m_NativeRatio / currentRatio;
Personal tools
Namespaces

Variants
Actions
Navigation
Extras
Toolbox