The right way to wrap your UI inside the safe area — Unity

How to restrict the UI inside the safe area unity
showing the UI inside the safe area unity
showing the UI inside the safe area unity
using UnityEngine;public class SafeArea : MonoBehaviour
{
private RectTransform _rectTransform;
private Rect _safeArea;
private Vector2 _minAnchor;
private Vector2 _maxAnchor;
private void Awake(){_rectTransform = GetComponent<RectTransform>();_safeArea = Screen.safeArea;_minAnchor = _safeArea.position;_maxAnchor = _minAnchor + _safeArea.size;_minAnchor.x /= Screen.width;_minAnchor.y /= Screen.height;_maxAnchor.x /= Screen.width;_maxAnchor.y /= Screen.height;_rectTransform.anchorMin = _minAnchor;_rectTransform.anchorMax = _maxAnchor;}}
how to show the UI only inside the safe area unity
How to set the UI inside the safe area unity

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Farrukh Sajjad

Farrukh Sajjad

Noob Game Dev | Back to posting weekly