
enum CameraType4 {
	Overhead = 0,
	ThirdPerson = 1,
}

var guiSkin : GUISkin;
var nativeVerticalResolution = 1200.0;
var initialType = CameraType4.Overhead;
var overheadCamera : Camera;
var thirdPersonCamera : Camera;
var character : GameObject;

// Private variables
private var type : CameraType4;

function Start() 
{
	// Make sure both cameras are defined
	if (!overheadCamera || !thirdPersonCamera)
	{
		print("Not all cameras defined, GUI disabled.");
		enabled = false;		
	}
	
	// Make sure the character is defined
	if (!character)
	{
		print("No character defined, GUI disabled.");
		enabled = false;
	}
	
	// Make sure the GUI Skin is defined
	if (!guiSkin)
	{
		print("No GUI Skin detected, GUI disabled.");
		enabled = false;
	}
	
	// initialize the camera type.  This is for convenience so I don't have to
	// use "initialType" everywhere
	type = initialType;
	
	// Make sure the correct camera is enabled by default
	updateCameras();
}

function OnGUI()
{
	// Set the skin
	GUI.skin = guiSkin;
	
	// Make the GUI independent of screen size
	GUI.matrix = Matrix4x4.TRS(
		Vector3.zero, 
		Quaternion.identity, 
		Vector3(Screen.height/nativeVerticalResolution, Screen.height/nativeVerticalResolution, 1));
		
	// Define the toggle button
	var scaledResolutionWidth = nativeVerticalResolution / Screen.height * Screen.width;
	var rect = Rect(scaledResolutionWidth - 210, 10, 200, 60);
	if (GUI.Button(rect, "Toggle Camera"))
	{
		// If pressed, change camera types
		if (type == CameraType4.Overhead)
			type = CameraType4.ThirdPerson;
		else
			type = CameraType4.Overhead;
		
		// Update which camera is enabled
		updateCameras();
	}
}

function updateCameras()
{
	// Disable both cameras
	overheadCamera.enabled = false;
	thirdPersonCamera.enabled = false;
	
	// Enable the current camera type
	if (type == CameraType4.Overhead)
	{
		overheadCamera.enabled = true;
		character.SetActiveRecursively(false);
	}
	else
	{
		thirdPersonCamera.enabled = true;
		character.SetActiveRecursively(true);
	}
}

// Make the script also execute in edit mode
@script ExecuteInEditMode()