我是编程新手,我制作了这个脚本,它根据您的输入生成一个读取XML文件的函数,我刚刚遇到了这个问题,尽管我不能在哪里访问名为“XMLtext”的变量,它是公开的,有人可以告诉我我做错了什么,并解释它,我尝试了各种各样的东西。封装简单
using UnityEngine;
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using System.Collections;
public class Data : MonoBehaviour {
public TextAsset XMLtext;
void Main() {
}
public static string XMLread (params string[] no) {
var XMLfile = XDocument.Parse();
var a = Data.XMLfile.Element ("data");
for (int i = 0; no[i] == null; i++) {
}
}
}
对不起,我应该提到XMLtext变量将在“var XMLfile = XDocument.Parse(XMLtext.text); – user2690614
是不是XMLText是统一框架的保留字吗?只是猜测.. – CaveCoder
好吧,我现在觉得自己像个白痴,我在声明前用“静态”解决了问题,尽管我之前尝试过,但没有成功。噢,有人可以解释为什么它需要静态前缀可以访问虽然? – user2690614