we are attempting to set up an online server and connect players to a server using Dark Rift, a collection of libraries. We are getting an error with a part of our code that checks when a player joins a game, it spawns a player connected to their ID:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DarkRift;
using DarkRift.Server;
using DarkRift.Client.Unity;
public class PlayerSpawner : MonoBehaviour
{
const byte SPAWN_TAG = 0;
[SerializeField]
[Tooltip("The DarkRift client to communicate on.")]
UnityClient client;
[SerializeField]
[Tooltip("The controllable player prefab.")]
GameObject controllablePrefab;
[SerializeField]
[Tooltip("The network controllable player prefab.")]
GameObject networkPrefab;
void Awake()
{
if (client == null)
{
Debug.LogError("Client unassigned in PlayerSpawner.");
Application.Quit();
}
if (controllablePrefab == null)
{
Debug.LogError("Controllable Prefab unassigned in PlayerSpawner.");
Application.Quit();
}
if (networkPrefab == null)
{
Debug.LogError("Network Prefab unassigned in PlayerSpawner.");
Application.Quit();
}
client.MessageReceived += SpawnPlayer;
}
void SpawnPlayer(object sender, MessageReceivedEventArgs e)
{
using (Message message = e.GetMessage())
using (DarkRiftReader reader = message.GetReader())
{
if (message.Tag == Tags.SpawnPlayerTag)
{
if (reader.Length % 17 != 0)
{
Debug.LogWarning("Received malformed spawn packet.");
return;
}
while (reader.Position < reader.Length)
{
ushort id = reader.ReadUInt16();
Vector3 position = new Vector3(0, 0);
GameObject obj;
if (id == client.ID)
{
obj = Instantiate(controllablePrefab, position, Quaternion.identity) as GameObject;
}
else
{
obj = Instantiate(networkPrefab, position, Quaternion.identity) as GameObject;
}
}
}
}
}
}
In the client.MessageRecieved += SpawnPlayer; line it is not giving SpawnPlayer the argument of the type (it wants the MessageRecievedEventArgs, but is getting something else instead we think). The error says:
No overload for 'SpawnPlayer' matches delegate 'EventHandler<MessageReceivedEventArgs>'[Assembly-CSharp] csharp(cs0123) [43, 9]
Thank you very much!