So I have an inactive gun object as a child of the player, and when i activate the gun object this message shows upp, but only when there’s another player in the room. (im using photon pun2)
Caught exception in OnEvent() for event code 200: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation.
UnityEngine.Debug:LogError (object)
Photon.Realtime.LoadBalancingClient:smile:ebugReturn (ExitGames.Client.Photon.DebugLevel,string) (at Assets/Photon/PhotonRealtime/Code/LoadBalancingClient.cs:2564)
ExitGames.Client.Photon.PeerBase/<>c__DisplayClass108_0:b__0 () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PeerBase.cs:1212)
ExitGames.Client.Photon.EnetPeer:smile:ispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/EnetPeer.cs:440)
ExitGames.Client.Photon.PhotonPeer:smile:ispatchIncomingCommands () (at D:/Dev/Work/photon-dotnet-sdk/PhotonDotNet/PhotonPeer.cs:1771)
Photon.Pun.PhotonHandler:smile:ispatch () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:221)
Photon.Pun.PhotonHandler:FixedUpdate () (at Assets/Photon/PhotonUnityNetworking/Code/PhotonHandler.cs:147)
I think this is where the problem occures.
void GiveGun()
{
Player[] players = FindObjectsOfType<Player>();
float furthestDistance = 0;
Player playerToGetWeapon = null;
for (int i = 0; i < players.Length; i++)
{
float distance = Vector2.Distance(players[i].transform.position, goal.position);
if (distance > furthestDistance)
{
furthestDistance = distance;
playerToGetWeapon = players[i];
}
}
photonView.RPC("SpawnGun", RpcTarget.AllBuffered, playerToGetWeapon.GetInstanceID());
}
[PunRPC]
void SpawnGun(int instanceID)
{
Player player = GameObject.Find("Player" + instanceID).GetComponent<Player>();
player.gun.gameObject.SetActive(true);
}
Can someone please help me with this? Also I should mention that the game works as it should, I have no idea why the error shows up.