Some questions: Custom room and player properties. Sync some info in room. Set Room closed.
Options
Hello! I'm novice in Photon but not novice in Unity.
I have some questions
1.How can I add custom properties to room and get it?
I was trying it:
I have a waiting room before starting the game... So there 2 questions:
2. How can I sync some infos. Like a integer, toggle(checkbox).
3. How can I remove lobby from visible after scene loading(GameStarting)
I have some questions
1.How can I add custom properties to room and get it?
I was trying it:
RoomOptions roomOptions = new RoomOptions(); roomOptions.CustomRoomProperties.Add("test", "simple"); PhotonNetwork.CreateRoom("text okay", roomOptions, null);Idk works it or no, but problem it's I can't get this key! How I should?
I have a waiting room before starting the game... So there 2 questions:
2. How can I sync some infos. Like a integer, toggle(checkbox).
3. How can I remove lobby from visible after scene loading(GameStarting)
0
Comments
-
Hi @RandomMan,
Thank you for choosing Photon and here is a not so random answer:
To get room properties after you join the room:string exampleValue = PhotonNetwork.room.customProperties["test"];
To set custom room properties:PhotonNetwork.room.SetCustomProperties(hashtable);
To close a room:PhotonNetwork.room.IsOpen = false;
To make a room invisible inside the lobby:PhotonNetwork.room.IsVisible = false;
0 -
I need to set custom properties when CreatingRoom, how is it possible using RoomOptions?
And Need get in lobby, like a room name etc...
Also thanks for Close answer, I think it need!
and I still don't know how to sync some checkboxes or infos players in room! (they will edit it in room)0 -
I can't understand your question:
Do you want to set custom room properties during creation, you're already doing it right:RoomOptions roomOptions = new RoomOptions(); roomOptions.CustomRoomProperties = new Hashtable() {{"test", "sample"}}; PhotonNetwork.CreateRoom("text okay", roomOptions, null);
Do you want to set custom room properties visible from the lobby during creation:
you just need to add their keys toRoomOptions.CustomRoomPropertiesForLobby
e.g.RoomOptions roomOptions = new RoomOptions(); roomOptions.CustomRoomProperties = new Hashtable() {{"test", "sample"}}; roomOptions.CustomRoomPropertiesForLobby = new string[] {"test"}; PhotonNetwork.CreateRoom("text okay", roomOptions, null);
0 -
But still question. How to sync player infos? Is possible to add to Player also CustomProperties like a level and get it?0
-
please use:
photonPlayer.SetCustomProperties(hashtable);
to get local player:PhotonNetwork.player
there are multiple ways to get other players, e.g.photonPlayer = PhotonPlayer.Get(actorNr);
0 -
Okay. How can I know actorNr?
And now I found, That I can't get CustomProperties! I tryingroomsList = PhotonNetwork.GetRoomList(); for (int i = 0; i < roomsList.Length; i++) { GameObject go = Instantiate(Resources.Load("RoomLine", typeof(GameObject)), RoomsPlace.transform) as GameObject; go.transform.FindChild("RoomName").GetComponent<Text>().text = roomsList[i].Name;//That's works go.transform.FindChild("TestElement").GetComponent<Text>().text = roomsList[i].CustomProperties["test"]; //That's not! }
And there I get error cannot convert type object to string.0 -
As I told you there are different ways to get players, e.g.
PhotonPlayer.GetNext()
-
PhotonPlayer.GetNextFor()
-
PhotonNetwork.otherPlayers
-
PhotonNetwork.playerList
// all players including local one
roomOptions.CustomRoomPropertiesForLobby = new string[] {"test"};
0 -
But I did it visible! It still says can't convert object to string because here I save it like string and get like an Object. Why?0
-
You just need a cast from object to string:
string stringValue = roomOrRoomInfo.CustomProperties["test"] as string; textUiComponent.text = stringValue;
0