Performance: First Unity project (Hello World scene)
This affects the initial load time and rendering speed of the Unity scene, impacting how quickly the user sees the Hello World message.
using UnityEngine; using UnityEngine.UI; public class HelloWorld : MonoBehaviour { public Text helloText; void Start() { helloText.text = "Hello World"; } }
using UnityEngine; public class HelloWorld : MonoBehaviour { void Start() { for (int i = 0; i < 1000; i++) { GameObject textObj = new GameObject("Text" + i); var text = textObj.AddComponent<UnityEngine.UI.Text>(); text.text = "Hello World"; } } }
| Pattern | GameObjects Created | Reflows | CPU Usage | Verdict |
|---|---|---|---|---|
| Creating 1000 UI Text objects | 1000 | 1000 | High | [X] Bad |
| Using one UI Text object and updating text | 1 | 1 | Low | [OK] Good |
Hello World scene in your first Unity project?textMeshProUGUI.text = "Hello World!"; is correct.using TMPro;
using UnityEngine;
public class HelloWorld : MonoBehaviour {
public TextMeshProUGUI messageText;
void Start() {
messageText.text = "Hello World!";
}
}using TMPro;
using UnityEngine;
public class HelloWorld : MonoBehaviour {
public TextMeshProUGUI messageText;
void Start() {
messageText.text = "Hello World!";
}
}Pass the test and this pattern moves unknown