Game Dev Cheat Sheet

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

anchorMin(0.5, 0.5)
anchorMax(0.5, 0.5)
pivot(0.5, 0.5)

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

HUD

Top-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.

min(0, 1)
max(1, 1)
pivot(0.5, 1)
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

HUD

Top-Right with a fixed size. Stays pinned to the top-right corner, maintaining its dimensions across all screen sizes.

min(1, 1)
max(1, 1)
pivot(1, 1)
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 Menu

Stretch-Both to cover the entire screen. Use for pause menus, loading screens, or fade-to-black transitions.

min(0, 0)
max(1, 1)
pivot(0.5, 0.5)
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

Dialogue

Centre with a fixed size. Perfect for dialogue boxes, confirmation prompts, or reward screens that float in the middle of the screen.

min(0.5, 0.5)
max(0.5, 0.5)
pivot(0.5, 0.5)
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

Mobile

Bottom-Stretch with a fixed height. Spans the full width at the bottom, commonly used for tab bars and navigation in mobile games.

min(0, 0)
max(1, 0)
pivot(0.5, 0)
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

HUD

Top-Centre with a fixed size. Sits at the top-centre for score counters, level indicators, or round timers.

min(0.5, 1)
max(0.5, 1)
pivot(0.5, 1)
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);