0
0
Unityframework~10 mins

Text and TextMeshPro 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 text of a UI Text component.

Unity
using UnityEngine;
using UnityEngine.UI;

public class Example : MonoBehaviour {
    public Text uiText;

    void Start() {
        uiText.[1] = "Hello World!";
    }
}
Drag options to blanks, or click blank then click option'
Acontent
Btext
Cvalue
Dstring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'content' or 'value' instead of 'text' property.
2fill in blank
medium

Complete the code to set the text of a TextMeshProUGUI component.

Unity
using TMPro;
using UnityEngine;

public class Example : MonoBehaviour {
    public TextMeshProUGUI tmpText;

    void Start() {
        tmpText.[1] = "Welcome to TextMeshPro!";
    }
}
Drag options to blanks, or click blank then click option'
Acontent
Bstring
Cvalue
Dtext
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to use 'content' or 'value' instead of 'text'.
3fill in blank
hard

Fix the error in the code to change the font size of a TextMeshProUGUI component.

Unity
using TMPro;
using UnityEngine;

public class Example : MonoBehaviour {
    public TextMeshProUGUI tmpText;

    void Start() {
        tmpText.fontSize [1] 36;
    }
}
Drag options to blanks, or click blank then click option'
A+=
B==
C=
D:=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '=' causes a syntax error.
4fill in blank
hard

Fill both blanks to create a dictionary mapping words to their lengths, but only include words longer than 4 characters.

Unity
var words = new string[] {"apple", "cat", "banana", "dog"};
var lengths = new Dictionary<string, int>() {
    {"apple", 5},
    {"banana", 6}
};

var filteredLengths = new Dictionary<string, int>();
foreach (var word in words) {
    if (word.[1] > 4) {
        filteredLengths[word] = word.[2];
    }
}
Drag options to blanks, or click blank then click option'
ALength
BCount
CLength()
DCount()
Attempts:
3 left
💡 Hint
Common Mistakes
Using Length() or Count() which are invalid for strings.
5fill in blank
hard

Fill all three blanks to create a dictionary from words to their uppercase forms, but only include words starting with 'a'.

Unity
var words = new string[] {"apple", "banana", "avocado", "cherry"};
var result = new Dictionary<string, string>();
foreach (var word in words) {
    if (word.[1]('a')) {
        result[[2]] = word.[3]();
    }
}
Drag options to blanks, or click blank then click option'
AStartsWith
Bword
CToUpper
DContains
Attempts:
3 left
💡 Hint
Common Mistakes
Using Contains instead of StartsWith.
Forgetting parentheses on ToUpper().