parent
777852a8f2
commit
40c50479bf
@ -0,0 +1,50 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class DialogSystem : MonoBehaviour
|
||||
{
|
||||
[Header("UI组件")]
|
||||
public Text textLable;
|
||||
[Header("文本文件")]
|
||||
public TextAsset textFile;
|
||||
public int index;
|
||||
List<string> textList = new List<string>();
|
||||
// Start is called before the first frame update
|
||||
void Awake()
|
||||
{
|
||||
GetTextFromFile(textFile);
|
||||
}
|
||||
private void OnEnable()
|
||||
{
|
||||
textLable.text = textList[index];
|
||||
index++;
|
||||
}
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
if (Input.GetKeyDown(KeyCode.X) && index == textList.Count)
|
||||
{
|
||||
gameObject.SetActive(false);
|
||||
index = 0;
|
||||
return;
|
||||
}
|
||||
if (Input.GetKeyDown(KeyCode.X))
|
||||
{
|
||||
textLable.text = textList[index];
|
||||
index++;
|
||||
}
|
||||
}
|
||||
void GetTextFromFile(TextAsset file)
|
||||
{
|
||||
textList.Clear();
|
||||
index = 0;
|
||||
var lineDate=file.text.Split('\n');
|
||||
foreach (var line in lineDate)
|
||||
{
|
||||
textList.Add(line);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue