OnEvent is not called when event is raised
i literally just copy pasted codes from pun v2 website
here's my script
using Photon.Pun;
using UnityEngine;
using ExitGames.Client.Photon;
using Photon.Realtime;
public class TestEvent : MonoBehaviourPunCallbacks
{
public const byte MoveUnitsToTargetPositionEventCode = 12;
public override void OnEnable() { PhotonNetwork.AddCallbackTarget(this); }
public override void OnDisable() { PhotonNetwork.RemoveCallbackTarget(this); }
private void Start()
{
Debug.Log("started");
SendMoveUnitsToTargetPositionEvent();
}
private void SendMoveUnitsToTargetPositionEvent()
{
string content = "hello";
RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All };
PhotonNetwork.RaiseEvent(MoveUnitsToTargetPositionEventCode, content, raiseEventOptions, SendOptions.SendReliable);
Debug.Log("string 1 = " + content);
}
public void OnEvent(EventData photonEvent)
{
Debug.Log("reached here");
byte eventCode = photonEvent.Code;
if (eventCode == MoveUnitsToTargetPositionEventCode)
{
string data = (string)photonEvent.CustomData;
Debug.Log("string2 = " + data);
}
}
}
to set up PUN2 in unity i just made an app in photon database and copy pasted app id in unity, i didnt do anything else.
what am i doing wrong here ?
here's my script
using Photon.Pun;
using UnityEngine;
using ExitGames.Client.Photon;
using Photon.Realtime;
public class TestEvent : MonoBehaviourPunCallbacks
{
public const byte MoveUnitsToTargetPositionEventCode = 12;
public override void OnEnable() { PhotonNetwork.AddCallbackTarget(this); }
public override void OnDisable() { PhotonNetwork.RemoveCallbackTarget(this); }
private void Start()
{
Debug.Log("started");
SendMoveUnitsToTargetPositionEvent();
}
private void SendMoveUnitsToTargetPositionEvent()
{
string content = "hello";
RaiseEventOptions raiseEventOptions = new RaiseEventOptions { Receivers = ReceiverGroup.All };
PhotonNetwork.RaiseEvent(MoveUnitsToTargetPositionEventCode, content, raiseEventOptions, SendOptions.SendReliable);
Debug.Log("string 1 = " + content);
}
public void OnEvent(EventData photonEvent)
{
Debug.Log("reached here");
byte eventCode = photonEvent.Code;
if (eventCode == MoveUnitsToTargetPositionEventCode)
{
string data = (string)photonEvent.CustomData;
Debug.Log("string2 = " + data);
}
}
}
to set up PUN2 in unity i just made an app in photon database and copy pasted app id in unity, i didnt do anything else.
what am i doing wrong here ?
0
Best Answer
-
I guess you missed hooking it up with IOnEventCallback interface which is mentioned in the documentation. It should be public class TestEvent : MonoBehaviourPunCallbacks, IOnEvenCallback2
Answers
-
I guess you missed hooking it up with IOnEventCallback interface which is mentioned in the documentation. It should be public class TestEvent : MonoBehaviourPunCallbacks, IOnEvenCallback2