Unity C#PlayerData对象变量= null

时间:2018-07-18 12:30:02

标签: c# unity3d null

所以我想从一个看起来像“ ID1 / Name1 / ID2 / Name2”的PHP文件中获取数据。 ID1和Name1是Player1的数据,Player1是名为“ OnlinePlayer”的单独类的对象。当我打印“ Player.name”时,它说为空。我认为这是PHP文件的错误,但是数组中填充了诸如pa [1] = Max

之类的数据

我做错了什么?

OnlinePlayer

public class OnlinePlayer {

    public string Name;
    public int ID;
    public int points;

    public OnlinePlayer(){}
}

GameRoom

public class GameRoom : MonoBehaviour {

string URL = "http://LINK TO SERVER/FILE.php";

public OnlinePlayer Player1 = new OnlinePlayer ();
public OnlinePlayer Player2 = new OnlinePlayer ();


void Start () {
    StartCoroutine (checkIn());
}


IEnumerator checkIn(){
    WWW w = new WWW (URL); //runs the php script
    yield return w; //waits until script is done

    string[] pa  = w.text.Split('/');

    if(pa.Length >= 2){
        Player1.ID = int.Parse(pa[0]);
        Player1.Name = pa [1].ToString();

        if(pa.Length == 2) {
            Player2.ID = PlayerPref.ID;
            Player2.Name = PlayerPref.nickname;
        }
    }if(pa.Length == 4) {
            Player2.ID = int.Parse(pa[3]) ;
            Player2.Name = pa [4].ToString();
            Player3.ID = PlayerPref.ID;
            Player3.Name = PlayerPref.nickname;
    }

    print (Player1.Name);
    print (pa[1]);       }//end CheckIn

print(Player1.Name)->空

print(pa [1])->最大

0 个答案:

没有答案