You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.1 KiB
51 lines
1.1 KiB
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);
|
|
}
|
|
|
|
}
|
|
}
|