简体   繁体   中英

syntax error in photon networking for unity

Only assignment, call, increment, decrement, and new object expressions can be used as a statement

I'm not sure of what this error is.

There are no other syntax errors in the code

using UnityEngine;
using System.Collections;

public class NetworkManager : MonoBehaviour {

    // Use this for initialization
    void Start () {
        PhotonNetwork.ConnectUsingSettings("1.0");
    }
    private const string roomName = "RoomName";
    private RoomInfo[] roomsList;

    void OnGUI()
    {
        if (!PhotonNetwork.connected)
        {
            GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
        }
        else if (PhotonNetwork.room == null)
        {
            // Create Room
            if (GUI.Button(new Rect(100, 100, 250, 100), "Start Server"))
                PhotonNetwork.CreateRoom(roomName + Guid.NewGuid().ToString("N"), true, true, 5);

            // Join Room
            if (roomsList != null)
            {
                for (int i = 0; i < roomsList.Length; i++)
                {
                    if (GUI.Button(new Rect(100, 250 + (110 * i), 250, 100), "Join " + roomsList[i].name))
                        PhotonNetwork.JoinRoom(roomsList[i].name);
                }
            }
        }
    }

    void OnReceivedRoomListUpdate()
    {
        roomsList = PhotonNetwork.GetRoomList();
    }
    void OnJoinedRoom()
    {
        Debug.Log("Connected to Room");
    }
}

It should be roomsList.GetLength(0) . See here

try

            int i = 0;
            foreach (RoomInfo game in PhotonNetwork.GetRoomList())
            {
                if (GUI.Button(new Rect(5, (40 * (i + 2)) + 10, Screen.width - 10, 40), "Join" + game.name, _skin.button))
                {
                    PhotonNetwork.JoinRoom(game.name);
                }
                i++;
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM