Source

Twisted Potions Double Trouble / Assets / Scripts / GUIManager.cs

using UnityEngine;
using System.Collections;

public class GUIManager : MonoBehaviour
{
	public enum GuiAnchor
	{
		bottomLeft=0,
		bottomRight
	};
	public int offset = 0;
	
	public GuiAnchor anchor = GuiAnchor.bottomLeft;
		
	void Awake ()
	{
		// Let's remove the UI on desktop versions
		// Later versions will only remove the iphone ui not all
		#if UNITY_STANDALONE_WIN || UNITY_STANDALONE_MAC || UNITY_WEBPLAYER
			Destroy(gameObject);
		#endif
		
		// To place this current gui layer on its correct position we'll 
		// check the camera current 0,0 and set it there.
		// It is neccesary that the gui objects are always placed under a camera
		// Since it server for 2 purposes:
		// a) The gui moves along with it as it's parented. 
		// b) It uses it to relocate to it's 0,0
		Camera camera = transform.parent.gameObject.camera;
		switch (anchor) {
			case GuiAnchor.bottomLeft:	
				Vector3 zeroPoint = camera.ViewportToWorldPoint (Vector3.zero);
				zeroPoint.z = gameObject.transform.position.z;
				zeroPoint.x += offset;
				gameObject.transform.position = zeroPoint;			
				break;
			
			case GuiAnchor.bottomRight:	
				Vector3 onePoint = camera.ViewportToWorldPoint (new Vector3(1,0,0));
				onePoint.z = gameObject.transform.position.z;
				onePoint.x += offset;
				gameObject.transform.position = onePoint;
				break;
		}
	}
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.