Witam, mam pewien problem z multiplayer.
Robię czat. Chcę go zrobić bez użycia prefabu playera.
Stworzyłem więc obiekt Networking z potrzebnymi skryptami (NetworkManager i HUD).
Zrobiłem także obiekt Manager z skryptem Chat i Network Identity (zaznaczone Local Player Authority)
Skrypt Chat:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class Chat : NetworkBehaviour {
public Text ChatPan; //tekst
public InputField messaging; //pole wejściowe
public void Update() // tutaj chciałęm dać client Authority
{
if(isServer)
this.GetComponent<NetworkIdentity>().AssignClientAuthority(this.GetComponent<NetworkIdentity>().connectionToClient);
}
public void OnStartAuthority()
{
Debug.Log("LOGGINED WITH AUTHORITY!");
}
void FixedUpdate() //to do wypisywania informacji
{
Debug.Log("AUTHORITY: "+this.GetComponent<NetworkIdentity>().hasAuthority.ToString());
Debug.Log("ConnectionToClient: " + this.GetComponent<NetworkIdentity>().connectionToClient);
Debug.Log("ConnectionToServer: " + this.GetComponent<NetworkIdentity>().connectionToServer);
}
public void SendNow()
{
Debug.Log("SendNow used");
CmdSendMessageNow(messaging.text);
//messaging.text="";
}
[ClientRpc]
public void RpcSend(string message)
{
ChatPan.text+="\n"+message;
}
[Command]
public void CmdSendMessageNow(string message)
{
RpcSend(message);
Debug.Log("CommandOK");
}
}
Po wpisaniu wiadomości u hosta, wysyła się poprawnie.
Lecz jeśli wpiszę coś u clienta, wywala taki błąd:
Trying to send command for object without authority.
UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
Chat:CallCmdSendMessageNow(String)
Chat:SendNow() (at Assets/Scripts/Chat.cs:46)
UnityEngine.EventSystems.EventSystem:Update()
Czytałem o tym dużo. Wiem, że host musi "dać authority" clientowi, lecz nie umiem wykonać tego.
Wiem tyle, że to musi wykonać host.