0
0
Unityframework~10 mins

Canvas and render modes 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 Canvas render mode to Screen Space - Overlay.

Unity
Canvas canvas = GetComponent<Canvas>();
canvas.renderMode = RenderMode.[1];
Drag options to blanks, or click blank then click option'
AOverlayScreenSpace
BWorldSpace
CScreenSpaceCamera
DScreenSpaceOverlay
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'WorldSpace' instead of 'ScreenSpaceOverlay' causes the UI to appear in 3D space.
Misspelling the render mode name.
2fill in blank
medium

Complete the code to assign a Camera to the Canvas for Screen Space - Camera mode.

Unity
Canvas canvas = GetComponent<Canvas>();
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.worldCamera = [1];
Drag options to blanks, or click blank then click option'
ACamera.main
Bthis
CgameObject
Dnull
Attempts:
3 left
💡 Hint
Common Mistakes
Assigning null causes the Canvas not to render properly.
Using 'gameObject' instead of a Camera reference.
3fill in blank
hard

Fix the error in setting the Canvas render mode to World Space.

Unity
Canvas canvas = GetComponent<Canvas>();
canvas.renderMode = RenderMode.[1];
Drag options to blanks, or click blank then click option'
AScreenSpaceOverlay
BScreenSpaceCamera
CWorldSpace
DWorld_Space
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'World_Space' causes a compile error.
Confusing Screen Space modes with World Space.
4fill in blank
hard

Fill both blanks to create a Canvas in World Space and set its size.

Unity
Canvas canvas = gameObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.[1];
RectTransform rt = canvas.GetComponent<RectTransform>();
rt.sizeDelta = new Vector2([2], 300);
Drag options to blanks, or click blank then click option'
AWorldSpace
BScreenSpaceOverlay
C500
D400
Attempts:
3 left
💡 Hint
Common Mistakes
Using ScreenSpaceOverlay with sizeDelta has no effect.
Setting sizeDelta width to 400 instead of 500.
5fill in blank
hard

Fill all three blanks to create a Canvas in Screen Space - Camera mode, assign the main camera, and set the plane distance.

Unity
Canvas canvas = gameObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.[1];
canvas.worldCamera = [2];
canvas.planeDistance = [3]f;
Drag options to blanks, or click blank then click option'
AWorldSpace
BCamera.main
C100
DScreenSpaceCamera
Attempts:
3 left
💡 Hint
Common Mistakes
Using WorldSpace render mode with planeDistance causes no effect.
Not assigning a camera causes UI not to render.