Unity 简单读取txt文档内容的方法

来源:互联网 发布:三菱plcfx3u编程手册 编辑:程序博客网 时间:2024/06/04 18:42

1.  新建一个txt文档,加入你想要的内容  再把编码换成UTF-8的编码方式  如图: 


2.我们再把我们保存好的txt文档放入unity工程当中。添加如下代码: 

using UnityEngine; using System.Collections;   public class ReadTxt : MonoBehaviour {      //这个变量就是我们用来存放我们的txt的.     public TextAsset testTxt;     // Use this for initialization     void Start () {          }          // Update is called once per frame     void Update () {          }       void OnGUI()     {         //显示出来         GUILayout.Label(testTxt.text);     } } 
3.效果如下图: 



0 0