UI Anchoring Cheat Sheet
Visual reference for Unity RectTransform anchor presets with C# code and common UI layout patterns.
Unity's RectTransform anchor system controls how UI elements scale and position across different screen sizes. Getting anchors wrong causes UI to break on different resolutions. This visual guide shows every anchor preset with a preview and C# code.
Anchor Presets
Centre
Fixed size, dead centre of the screen. Use for crosshairs, dialogue popups, loading spinners, or modal windows.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0.5f, 0.5f);
rt.anchorMax = new Vector2(0.5f, 0.5f);
rt.pivot = new Vector2(0.5f, 0.5f);Common Patterns
Practical anchor configurations for real game UI. Each includes the full C# setup code you can copy directly into your project.
Health Bar
HUDTop-Stretch with a fixed height. Spans the full width at the top of the screen, commonly used for health or stamina bars in action games.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0f, 1f);
rt.anchorMax = new Vector2(1f, 1f);
rt.pivot = new Vector2(0.5f, 1f);
rt.sizeDelta = new Vector2(0, 40);
rt.anchoredPosition = new Vector2(0, -10);Minimap
HUDTop-Right with a fixed size. Stays pinned to the top-right corner, maintaining its dimensions across all screen sizes.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(1f, 1f);
rt.anchorMax = new Vector2(1f, 1f);
rt.pivot = new Vector2(1f, 1f);
rt.sizeDelta = new Vector2(200, 200);
rt.anchoredPosition = new Vector2(-10, -10);Full-Screen Overlay
Pause MenuStretch-Both to cover the entire screen. Use for pause menus, loading screens, or fade-to-black transitions.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0f, 0f);
rt.anchorMax = new Vector2(1f, 1f);
rt.pivot = new Vector2(0.5f, 0.5f);
rt.sizeDelta = Vector2.zero;
rt.anchoredPosition = Vector2.zero;Centred Popup
DialogueCentre with a fixed size. Perfect for dialogue boxes, confirmation prompts, or reward screens that float in the middle of the screen.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0.5f, 0.5f);
rt.anchorMax = new Vector2(0.5f, 0.5f);
rt.pivot = new Vector2(0.5f, 0.5f);
rt.sizeDelta = new Vector2(400, 300);
rt.anchoredPosition = Vector2.zero;Bottom Nav Bar
MobileBottom-Stretch with a fixed height. Spans the full width at the bottom, commonly used for tab bars and navigation in mobile games.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0f, 0f);
rt.anchorMax = new Vector2(1f, 0f);
rt.pivot = new Vector2(0.5f, 0f);
rt.sizeDelta = new Vector2(0, 60);
rt.anchoredPosition = Vector2.zero;Score Text
HUDTop-Centre with a fixed size. Sits at the top-centre for score counters, level indicators, or round timers.
RectTransform rt = GetComponent<RectTransform>();
rt.anchorMin = new Vector2(0.5f, 1f);
rt.anchorMax = new Vector2(0.5f, 1f);
rt.pivot = new Vector2(0.5f, 1f);
rt.sizeDelta = new Vector2(200, 50);
rt.anchoredPosition = new Vector2(0, -10);