0
0
Unityframework~10 mins

Anchoring and responsive UI in Unity - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the anchor of a RectTransform to the center.

Unity
rectTransform.anchorMin = new Vector2([1], [1]);
rectTransform.anchorMax = new Vector2([1], [1]);
Drag options to blanks, or click blank then click option'
A0.5
B0
C1
D-0.5
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 1 places the anchor at edges, not center.
Negative values are invalid for anchors.
2fill in blank
medium

Complete the code to make the UI element stretch horizontally by setting anchorMax.x to the right edge.

Unity
rectTransform.anchorMax = new Vector2([1], rectTransform.anchorMax.y);
Drag options to blanks, or click blank then click option'
A1
B0.5
C0
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 0.5 will not stretch to the right edge.
Negative values are invalid.
3fill in blank
hard

Fix the error in setting the pivot point to the bottom-left corner.

Unity
rectTransform.pivot = new Vector2([1], 0);
Drag options to blanks, or click blank then click option'
A1
B0.5
C-0.5
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0.5 centers the pivot.
Negative values are invalid.
4fill in blank
hard

Fill both blanks to create a RectTransform that stretches fully with a 10 pixel margin on all sides.

Unity
rectTransform.offsetMin = new Vector2([1], [1]);
rectTransform.offsetMax = new Vector2([2], [2]);
Drag options to blanks, or click blank then click option'
A10
B-10
C0
D5
Attempts:
3 left
💡 Hint
Common Mistakes
Using positive values for offsetMax causes incorrect margins.
Using zero removes margins.
5fill in blank
hard

Fill all three blanks to set anchors and pivot so the UI element stays fixed to the top-right corner.

Unity
rectTransform.anchorMin = new Vector2([1], [2]);
rectTransform.anchorMax = new Vector2([1], [2]);
rectTransform.pivot = new Vector2([3], [3]);
Drag options to blanks, or click blank then click option'
A0
B1
C0.5
D-1
Attempts:
3 left
💡 Hint
Common Mistakes
Using 0 or 0.5 for anchors or pivot will not fix the element to top-right.
Negative values are invalid.