2013-04-13 47 views
2

我需要創建一個XML文本文件,並通過(使用框)使用腳本在場景中的文本顯示?我創建了一個xml文本文件,即位於c Drive中。請參閱我的下面的代碼,並通過使用C#幫助我。下面的代碼使用ngui標籤。但使用框顯示很好。如何使用腳本創建xml文本並在場景中顯示文本?

using UnityEngine; 
using System.Collections; 
using System.Xml; 
using System.IO; 

public class Xml : MonoBehaviour 
{ 
    // Use this for initialization 
    void Start() 
    { 
     XmlDocument xml=new XmlDocument(); 
     xml.Load(Application.dataPath+"/Resources/text.xml"); 
    } 

    // Update is called once per frame 
    void Update() { } 

    void OnGUI() 
    { 
     UILabel subtitle = GameObject.Find("Label").GetComponent(); 
     subtitle.text = ""; 
    } 
} 

回答

1

如果你只是想從XML文件中的文本,你就不能使用你的讀者的InnerXml財產?您需要將XmlDocument移動爲行爲的成員變量,以便您可以訪問OnGUI中的文本,而無需在每一幀重新加載它。

subtitle.text = xml.InnerXml; 

如果你想要做一些更sophisticaed,通過XMLDocument方法看看,看看如何瀏覽一個XMLFILE

+0

太謝謝你了.... – KasiReddy

相關問題