Unity从资源加载文本 [英] Unity Load text from resources
本文介绍了Unity从资源加载文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我可以使用以下内容更改UILabel
(命名为)的文本:
I'm able to change the text of a UILabel
(named about) with the following:
using UnityEngine;
using System.Collections;
public class about : MonoBehaviour
{
void Start ()
{
UILabel lbl = GetComponent<UILabel>();
lbl.text = "Hello World!";
}
}
但是,当我想从资源(Assets/Resources/about.txt
)中的文本文件中加载标签文本时,事情却变了
However things go awry when I want to load the label text from a text file in resources (Assets/Resources/about.txt
)
lbl.text = Resources.Load(Application.dataPath + "/Resources/about") as String
所以我不确定哪里出了问题,是的,我已经此处.
So I'm not sure where I'm going wrong, and yes I have looked here.
推荐答案
只需使用此:
TextAsset mytxtData=(TextAsset)Resources.Load("MyText");
string txt=mytxtData.text;
,您可以使用txt
字符串满足您的要求,只需确保MyText.txt
在Assets > Resources
and you can use the txt
string to fulfill your requirement, just make sure that MyText.txt
is in Assets > Resources
这篇关于Unity从资源加载文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文