Complete the code to set the text of a UI Text component.
using UnityEngine; using UnityEngine.UI; public class Example : MonoBehaviour { public Text uiText; void Start() { uiText.[1] = "Hello World!"; } }
The Text component uses the text property to set its displayed string.
Complete the code to set the text of a TextMeshProUGUI component.
using TMPro; using UnityEngine; public class Example : MonoBehaviour { public TextMeshProUGUI tmpText; void Start() { tmpText.[1] = "Welcome to TextMeshPro!"; } }
TextMeshProUGUI uses the text property to set the displayed string, similar to the UI Text component.
Fix the error in the code to change the font size of a TextMeshProUGUI component.
using TMPro; using UnityEngine; public class Example : MonoBehaviour { public TextMeshProUGUI tmpText; void Start() { tmpText.fontSize [1] 36; } }
To assign a new font size, use the assignment operator =. Using == is a comparison, not assignment.
Fill both blanks to create a dictionary mapping words to their lengths, but only include words longer than 4 characters.
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];
}
}Length() or Count() which are invalid for strings.In C#, strings have a Length property (without parentheses) to get their length.
Fill all three blanks to create a dictionary from words to their uppercase forms, but only include words starting with 'a'.
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]();
}
}Contains instead of StartsWith.ToUpper().Use StartsWith('a') to check the first letter, use word as the dictionary key, and ToUpper() to convert the word to uppercase.