How to use SetCustomProperties?
Options
Hello, please help.
I can't figure out how to synchronize a boolean variable using SetCustomProperties.
// Script closing and opening the door.
Code:
How to use it in PUN2?
Thanks : 3
I can't figure out how to synchronize a boolean variable using SetCustomProperties.
// Script closing and opening the door.
Code:
public void Invert(Transform player) { target = player; isOpen = (bool)Photon.Realtime.Player.CustomProperties["IsOpen"]; ExitGames.Client.Photon.Hashtable hash = new ExitGames.Client.Photon.Hashtable(); hash.Add("IsOpen",isOpen); isOpen = !isOpen; Photon.Realtime.Player.SetCustomProperties(hash); if(isOpen == true) { gameObject.GetComponent<AudioSource>().clip = AudioClosed; gameObject.GetComponent<AudioSource>().Play(); } else { gameObject.GetComponent<AudioSource>().clip = AudioOpen; gameObject.GetComponent<AudioSource>().Play(); } }ERRORS:
Assets/door.cs(53,41): error CS0120: An object reference is required to access non-static member `Photon.Realtime.Player.CustomProperties'
Assets/door.cs(57,26): error CS0120: An object reference is required to access non-static member `Photon.Realtime.Player.SetCustomProperties(ExitGames.Client.Photon.Hashtable, ExitGames.Client.Photon.Hashtable, Photon.Realtime.WebFlags)'
Assets/door.cs(57,26): error CS0120: An object reference is required to access non-static member `Photon.Realtime.Player.SetCustomProperties(ExitGames.Client.Photon.Hashtable, ExitGames.Client.Photon.Hashtable, Photon.Realtime.WebFlags)'
How to use it in PUN2?
Thanks : 3
0
Comments
-
Hi @KirillAnto,
Thank you for choosing Photon!
1. You need to changePhoton.Realtime.Player
(which is a namespaced class name and not a variable name) with the actual reference to the player object instance.
For example:
local player:PhotonNetwork.LocalPlayer
.
2. There is already a well-known (default, predefined, native) ROOM property named "IsOpen" (since it's not a custom property its key is not really a string though). So if you want to change its value:PhotonNetwork.CurrentRoom.IsOpen = isOpen;
But maybe you want to have a PLAYER property, a CUSTOM one, named "IsOpen"?
I highly recommend starting and finishing "PUN Basics Tutorial".0