So lately i've been trying to work on weapon switching,
what i did is that i made the player change the weapon locally first (offline), then i change the player Custom Properties which is "currentWeapon" to the weapon index in the array and then in the server i used the Callback method (OnPhotonPlayerPropertiesChanged) to send the weapon index of the player who switched the weapon to all players
I'm still trying to figure out a way if you can help me out with an idea to send all players the function weapon switch as an RPC.. Thanks![:) :)]()
here's the code:
what i did is that i made the player change the weapon locally first (offline), then i change the player Custom Properties which is "currentWeapon" to the weapon index in the array and then in the server i used the Callback method (OnPhotonPlayerPropertiesChanged) to send the weapon index of the player who switched the weapon to all players
I'm still trying to figure out a way if you can help me out with an idea to send all players the function weapon switch as an RPC.. Thanks

here's the code:
void Start()
{
WeaponHash = new Hashtable() { { "currentWeapon", Array.IndexOf(Weapons, currentWeapon) } } ;
PhotonNetwork.player.SetCustomProperties( WeaponHash );
}
void SwitchWeapon(PlayerWeapon weapon)
{
//PhotonNetwork.player.SetCustomProperties()
foreach (PlayerWeapon w in Weapons)
{
if(weapon != w)
{
w.gameObject.SetActive(false);
}
else
{
WeaponHash["currentWeapon"] = Array.IndexOf(Weapons,weapon);
if(PhotonNetwork.player.IsLocal)
{
PhotonNetwork.player.SetCustomProperties(WeaponHash);
}
currentWeapon = weapon;
weapon.gameObject.SetActive(true);
}
}
}
void OnPhotonPlayerPropertiesChanged(object[] hash)
{
PhotonPlayer player = hash[0] as PhotonPlayer;
Hashtable data = hash[1] as Hashtable;
if (player.ID == PhotonNetwork.player.ID)
return;
Debug.Log(Weapons[(int)data["currentWeapon"]].name);
//SwitchWeapon(Weapons[(int)data["currentWeapon"]]);
}
{
WeaponHash = new Hashtable() { { "currentWeapon", Array.IndexOf(Weapons, currentWeapon) } } ;
PhotonNetwork.player.SetCustomProperties( WeaponHash );
}
void SwitchWeapon(PlayerWeapon weapon)
{
//PhotonNetwork.player.SetCustomProperties()
foreach (PlayerWeapon w in Weapons)
{
if(weapon != w)
{
w.gameObject.SetActive(false);
}
else
{
WeaponHash["currentWeapon"] = Array.IndexOf(Weapons,weapon);
if(PhotonNetwork.player.IsLocal)
{
PhotonNetwork.player.SetCustomProperties(WeaponHash);
}
currentWeapon = weapon;
weapon.gameObject.SetActive(true);
}
}
}
void OnPhotonPlayerPropertiesChanged(object[] hash)
{
PhotonPlayer player = hash[0] as PhotonPlayer;
Hashtable data = hash[1] as Hashtable;
if (player.ID == PhotonNetwork.player.ID)
return;
Debug.Log(Weapons[(int)data["currentWeapon"]].name);
//SwitchWeapon(Weapons[(int)data["currentWeapon"]]);
}