Unity3D文本在Android中构建时不会显示

时间:2017-03-16 02:11:50

标签: android unity3d text build

它适用于Unity,但它在Android中构建时却无法运行。这是我的代码。

<image>

这是截图。

Unity'

但这些文字没有出现在Android上。

Android'

我该如何解决这个问题?

  

文本文件位置:资产/资源/ Magnelli_0.27.txt

2 个答案:

答案 0 :(得分:2)

我解决了这个问题!!我关注了@Gunther Fox的评论,它正在开发Android!

answer

1. private TextAsset asset;
2. private string str;
3. private string[] names;
4. private Vector3 ViewPosition;
5. private double ViewZPosition;
6. private int length;
7. private double[] arrZ;
8. private double[] arrCV; 
9. 
10. // Use this for initialization
11. void Start () {
12.     Screen.sleepTimeout = SleepTimeout.NeverSleep;
13. 
14.     asset = Resources.Load ("Magnelli_0.27")as TextAsset;
15. 
16.     str = asset.text;
17.     names = str.Split('\n');
18.     length = names.Length;
19. 
20.     arrZ = new double[length];
21.     arrCV = new double[length];
22. 
23. }
24. 
25. // Update is called once per frame
26. void Update () {
27. 
28.     ViewPosition = GameObject.FindWithTag("MainCamera").transform.position;
29.     ViewZPosition = ViewPosition.z;
30. 
31.     TextReader txtreader = new StringReader (asset.text);
32.     StringReader streader = new StringReader (asset.text);
33. 
34.     string txt = "";
35. 
36.     for (int i = 0; i < length; ++i) {
37. 
38.         txt = streader.ReadLine();
39.         string[] sprite = txt.Split (' ');
40. 
41.         arrZ[i] = Convert.ToDouble(sprite[0]);
42.         arrCV[i] = Convert.ToDouble(sprite[1]);
43.     }
44.     for (int i = 0; i < length; i++) {
45.         
46.         if ((arrZ[i])*100-0.2 < ViewZPosition & (arrZ[i])*100+0.2 > ViewZPosition)
47.         {
48. 
49.             GetComponent<Text>().text = "redshift z : " + ViewZPosition*0.01 + "\nComoving Volume : " + arrCV[i] + " Gpc³";
50.         }
51.     }
52. }

答案 1 :(得分:0)

请使用StringReader将文件Magnelli_0.27作为TextAsset放入Resouce文件夹和每行读取器行。我认为当你构建另一个操作系统路径时,有价值的错误将会出错,然后它就不会出现文本。

https://msdn.microsoft.com/en-us/library/system.io.stringreader.readline(v=vs.110).aspx