GuiRatioFixer

From Unify Community Wiki
(Difference between revisions)
Jump to: navigation, search
(Boo)
Line 1: Line 1:
 
Author: Jon (Aarku)
 
Author: Jon (Aarku)
----
+
 
 +
== Description ==
 
Use this on a guiText or guiTexture object to automatically have them adjust their aspect ratio when the game starts.
 
Use this on a guiText or guiTexture object to automatically have them adjust their aspect ratio when the game starts.
  
==C#==
+
== Usage ==
 +
 
 +
Attach the script to a game object containing a GUIText or a GUITexture.
 +
 
 +
== C# - GuiRatioFixer.cs ==
 
  using UnityEngine;
 
  using UnityEngine;
 
  using System.Collections;
 
  using System.Collections;
Line 23: Line 28:
 
 
 
 
 
  }
 
  }
==Boo==
+
==Boo - GuiRatioFixer.boo ==
 
  import UnityEngine
 
  import UnityEngine
 
   
 
   
Line 38: Line 43:
 
  transform.localScale = scale
 
  transform.localScale = scale
  
==Javascript==
+
==Javascript - GuiRatioFixer.js ==
 
  // 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.

Revision as of 06:52, 1 December 2005

Author: Jon (Aarku)

Contents

Description

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

Usage

Attach the script to a game object containing a GUIText or a GUITexture.

C# - GuiRatioFixer.cs

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 - GuiRatioFixer.boo

import UnityEngine

# 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 - GuiRatioFixer.js

// 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