Skip to content

Instantly share code, notes, and snippets.

@WizzardMaker
Created December 18, 2015 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save WizzardMaker/93be086fcbf333ab93ef to your computer and use it in GitHub Desktop.
Save WizzardMaker/93be086fcbf333ab93ef to your computer and use it in GitHub Desktop.
This script adds a border to the top or the side, this scripts needs CameraSize.cs
using UnityEngine;
using System.Collections;
namespace StandardAssets{
/// <summary>
/// Adds a border to the top or the side.
/// Add this one to the child camera!
/// </summary>
[ExecuteInEditMode]
public class CameraBorder : MonoBehaviour {
/// <summary>
/// The border Texture (a 1x1 black dot is enough)
/// </summary>
public Texture border;
void OnGUI() {
//Ensure were on the top
GUI.depth = 10;
//Not needed, but to be sure
GUI.color = Color.black;
if (!CameraSize.letterbox) {
GUI.DrawTexture(new Rect(0, 0, Camera.main.pixelRect.x, GetComponent<Camera>().pixelRect.height), border);
GUI.DrawTexture(new Rect(Camera.main.pixelRect.width + Camera.main.pixelRect.x, 0, GetComponent<Camera>().pixelRect.width - Camera.main.pixelRect.width, GetComponent<Camera>().pixelRect.height), border);
} else {
GUI.DrawTexture(new Rect(0, 0, Camera.main.pixelRect.width,Camera.main.pixelRect.y), border);
GUI.DrawTexture(new Rect(0,Maths.PixelToRect(Camera.main.pixelRect.y), Camera.main.pixelRect.width, Camera.main.pixelRect.y), border);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment