[HELP] Photon Join Room
Options
miera
✭
Hi,
I tried to retrieve the room name from the code and appear it on the text so that when player want to join room they just can clicked on the text. However, I cannot get the room name.
I tried to retrieve the room name from the code and appear it on the text so that when player want to join room they just can clicked on the text. However, I cannot get the room name.
public RoomInfo RoomInfo { get; private set; } public void SetRoomInfo(RoomInfo roomInfo) { RoomInfo = roomInfo; _text.text = roomInfo.MaxPlayers + ", " + roomInfo.Name; roomname = RoomInfo.Name; Debug.Log("Room Name : " + roomname); } public void OnClick_Button() { //Debug.Log("Room Name : " + RoomInfo.Name); Debug.Log("Room Name : " + roomname); Debug.Log("Joining room in the list"); PhotonNetwork.JoinRoom(roomname,null); Debug.Log("Room Listing Menu : Join Room"); }How can I get the room name in RoomInfo?
0
Comments
-
public void OnClick_Button() { //Debug.Log("Room Name : " + RoomInfo.Name); <b class="Bold">Debug.Log("Room Name : " + roomname);</b> Debug.Log("Joining room in the list"); PhotonNetwork.JoinRoom(roomname,null); Debug.Log("Room Listing Menu : Join Room"); }
The project cannot read the bold line when i tried to debug log it on console.
The console show it like this.
https://imgur.com/wtUK4fd
0 -
[SerializeField] private RoomListing _roomListing;
- SetRoomInfo is in RoomListing.cspublic override void OnRoomListUpdate(List<RoomInfo> roomList) { foreach (RoomInfo info in roomList) { //remove from room list. if (info.RemovedFromList) { int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name); if(index != -1) { Destroy(_listing[index].gameObject); _listing.RemoveAt(index); } } //added rooms to list. else { int index = _listing.FindIndex(x => x.RoomInfo.Name == info.Name); if (index == -1) { RoomListing listing = <b class="Bold">Instantiate(_roomListing, _content);</b> if (listing != null) { listing.SetRoomInfo(info); _listing.Add(listing); } } } } }
- SetRoomInfo will be instantiate when the player want to joined the room. It will display on the scroll view which room has been created.public void SetRoomInfo<b class="Bold">(RoomInfo roomInfo)</b> { RoomInfo = roomInfo; _text.text = roomInfo.MaxPlayers + " , " + roomInfo.Name; <b class="Bold">roomname = RoomInfo.Name;</b> Debug.Log("Room Name : " + roomname); }
For your reference, here I attach my Github project link
https://github.com/project-neuromender/SIP.git
0 -
The code looks OK.
Somehow either:
-RoomInfo.Name
is null or empty initially
or
-RoomInfo.Name
orroomname
becomes null or empty at some point.
I suggest you change:roomname = RoomInfo.Name;
toroomname = roomInfo.Name;
and retry.0 -
I tried this but it still the same. Once public void OnClick_Button() is being call it can take the roomname = roomInfo.Name; as the variable are not being readable in public void OnClick_Button()0