Hi guys! I really cant handle a problem with sending messages. Every time when I try to send message i get “NullReferenceException: Object reference not set to an instance of an object
Message+MasterClient.RegisterHost (System.String name) (at Assets/Message.cs:27)
Message.Update () (at Assets/Message.cs:34)”. Here is my code, please help if possible
Client:
using UnityEngine;
using UnityEngine.Networking;
public class Message : NetworkBehaviour
{
class RegisterHostMessage : MessageBase
{
public string gameName;
public string comment;
public bool passwordProtected;
}
class MasterClient
{
public NetworkClient client;
public const short RegisterHotsMsgId = 888;
public void RegisterHost(string name)
{
RegisterHostMessage msg = new RegisterHostMessage();
msg.gameName = name;
msg.comment = "test";
msg.passwordProtected = false;
client.Send(RegisterHotsMsgId, msg);
}
}
void Update()
{
MasterClient mast = new MasterClient ();
mast.RegisterHost ("works");
}
}
Server: using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class ServerStart : NetworkBehaviour {
void Start()
{
Debug.Log ("Registering server callbacks");
}
void Update()
{
NetworkServer.RegisterHandler(888, OnMessage);
}
void OnMessage(NetworkMessage netMsg)
{
Debug.Log ("Client get");
}
}