一、設定對話框
於Hierarchy中,從Prefabs內拉入Canvas,並於其下方新增Panel作為對話框和角色姓名框,並新增Text作為文字內容。
其中對話框的圖片是使用之前下載素材包內的圖片,也可以另外用自己喜歡的圖片。
2、於Scripts新增DialogManager.cs,並撰寫程式碼:
using UnityEngine.UI; using TMPro;
public TextMeshProUGUI dialogText; public TextMeshProUGUI nameText; public GameObject dialogBox; public GameObject nameBox;
public string[] dialogLines; public int currentLines;
dialogText.text = dialogLines[currentLines];
3、將Canvas的屬性欄新增DialogManager.cs,並將對應的物件拉入各變數中,其中DiaglogLines可自行給數字,下方會依數字產生對應的空格,可於下方打任意內容。當遊戲模擬時會出現Dialog Lines中序號為CurrentLines數字的文字內容。
備註:UNITY無中文字,若要顯示中文字請參考此教學: