RPCs and RaiseEvent problem
I don't have problem to: connect server, enter room and sync scene, leave room and exit from connection.
I successfully implemented PRCs and RaiseEvent (as described on https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent) but I'm unable to leave room or destroy network.
What I'm making wrong ?
Here my code:
using ExitGames.Client.Photon;
using System.Collections;
[...]
public class GameManager : MonoBehaviourPunCallbacks
{
[...]
public override void OnEnable()
{
PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
}
public override void OnDisable()
{
PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
}
public void OnEvent(EventData photonEvent)
{
byte eventCode = photonEvent.Code;
if (eventCode == ReceivedDamage.PlayerDed)
{
int _viewID = (int)photonEvent.CustomData;
StopGame(_viewID);
}
}
and on the other class I have
public class ReceivedDamage : MonoBehaviourPunCallbacks
{
public const byte PlayerDed = 1;
[...on my function I will have...]
int content = _ViewId;
RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All };
PhotonNetwork.RaiseEvent(PlayerDed, content, raiseEventOptions, SendOptions.SendReliable);
If I remove the 3 event on GameManager I can leave room and disconnect all, otherwise no: PhotonNetwork destroy only my PlayerObject (the first object Instantiate) and stop. On log writes:
Network destroy Instantiated GO: MyPlayer
Someone can help me?
Thanks
Best Answer
-
I fixed it!
Solution is use the first example explained in doc. So with these methods all works.
private void OnEnable()
{
PhotonNetwork.AddCallbackTarget(this);
}
private void OnDisable()
{
PhotonNetwork.RemoveCallbackTarget(this);
}
public void OnEvent(EventData photonEvent)
{
byte eventCode = photonEvent.Code;
if (eventCode == ReceivedDamage.PlayerDed)
{
int _viewID = (int)photonEvent.CustomData;
StopGame(_viewID);
}
}
Hope can help someone
R.
1
Answers
-
I fixed it!
Solution is use the first example explained in doc. So with these methods all works.
private void OnEnable()
{
PhotonNetwork.AddCallbackTarget(this);
}
private void OnDisable()
{
PhotonNetwork.RemoveCallbackTarget(this);
}
public void OnEvent(EventData photonEvent)
{
byte eventCode = photonEvent.Code;
if (eventCode == ReceivedDamage.PlayerDed)
{
int _viewID = (int)photonEvent.CustomData;
StopGame(_viewID);
}
}
Hope can help someone
R.
1