Trying to send command for object without authority
Hello everyone!
I'm trying instantiate some GameObjects on LAN Match on the Scene. If you're the host, all works perfectly, GameObjects can be instantiate and you can see them all on Host and Client. The problem is when I try instantiate the GameObjects on the client, the console tells me this:
Trying to send command for object without authority. UnityEngine.Networking.NetworkBehaviour:SendCommandInternal(NetworkWriter, Int32, String)
And instantiate doesn't work. I don't know how to fix this so, if you know what's the problem, please tell me... If you want see something more except the next script, tell me on comments, thanks!
Canvas:
Button:
Here's the Script (This isn't all script, I just post the basic because it's too long):
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.Networking;
public class InstanceUnitats : NetworkBehaviour {
//Unidades Bytesonians //Botones Bytesonians
public GameObject unitatBasicBS; public GameObject buttonBasicBS;
void Update()
{
if(!isLocalPlayer)
{
return;
}
public void SelectBoton(string accion)
{
switch (accion)
{
//Bytesonians
case "BASICAB": CmdBB (); break;
}
}
//-----------------------BYTESONIANS-----------------------\\
[Command]
void CmdBB()
{
//Si el numero de unidades seleccionadas es mayor o igual a 0...
if (StructManager.VG.unidadBasicaBS > 0)
{
//Instanciamos
GameObject newUBasicBS = Instantiate (unitatBasicBS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadBasicaBS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUBasicBS;
if(StructManager.VG.unidadBasicaBS <= 0)
{
buttonBasicBS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUBasicBS);
}
}
}
screenshot-1.png
(63.8 kB)
screenshot-2.png
(45.6 kB)
Comment