Skip to content

Instantly share code, notes, and snippets.

View MeHigh9407's full-sized avatar
🎯
Focusing

MeHigh9407

🎯
Focusing
View GitHub Profile
@MeHigh9407
MeHigh9407 / PinToSafeArea.cs
Created June 24, 2021 19:16 — forked from SeanMcTex/PinToSafeArea.cs
Restrict Unity UI to an iPhone X or other Mobile Device's Safe Area
using UnityEngine;
/// <summary>
/// Resizes a UI element with a RectTransform to respect the safe areas of the current device.
/// This is particularly useful on an iPhone X, where we have to avoid the notch and the screen
/// corners.
///
/// The easiest way to use it is to create a root Canvas object, attach this script to a game object called "SafeAreaContainer"
/// that is the child of the root canvas, and then layout the UI elements within the SafeAreaContainer, which
/// will adjust size appropriately for the current device./// </summary>