Good, I'm trying to instantiate GameObjects in a LAN game in the scene from some buttons I have so you can choose which one you want to instantiate. From the Host everything goes perfect, I can instantiate the GameObjects and both Host as in the client it looks perfectly synchronized. The problem is that from the client I get the following error:
Trying to send command for object without authority. UnityEngine.Networking.NetworkBehaviour: SendCommandInternal (NetworkWriter, Int32, String)
Here I leave the Script
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using UnityEngine.Networking;
public class InstanceUnitats : NetworkBehaviour {
//Parents Unitats Canvas
private GameObject parentBytesonian;
private GameObject parentHominis;
//Unidades Bytesonians //Botones Bytesonians
public GameObject unitatBasicBS; public GameObject buttonBasicBS;
public GameObject unitatHeavyBS; public GameObject buttonHeavyBS;
public GameObject unitatVehicleBS; public GameObject buttonVehicleBS;
public GameObject unitatMeleeBS; public GameObject buttonMeleeBS;
public GameObject unitatGeneralBS; public GameObject buttonGeneralBS;
//Unidades Bytesonians //Botones Bytesonians
public GameObject unitatBasicHS; public GameObject buttonBasicHS;
public GameObject unitatHeavyHS; public GameObject buttonHeavyHS;
public GameObject unitatVehicleOFHS; public GameObject buttonVehicleOFHS;
public GameObject unitatVehicleTRHS; public GameObject buttonVehicleTRHS;
public GameObject unitatMeleeHS; public GameObject buttonMeleeHS;
public GameObject unitatGeneralHS; public GameObject buttonGeneralHS;
//Mouse
public Vector3 mousePosition;
void Awake()
{
parentBytesonian = gameObject.transform.Find ("BYTESONIANS").gameObject;
parentHominis = gameObject.transform.Find ("HOMINIS").gameObject;
}
void Start()
{
//Inicializamos los generales siempre a 1
StructManager.VG.unidadGeneralBS = 1;
StructManager.VG.unidadGeneralHS = 1;
//Si la bool es falsa, puedes escoger las unidades Humanas
if (StructManager.VG.razaSelected == false)
{
parentHominis.SetActive (true);
}
//Si no, puedes escoger las unidades Bytesonians
else
{
parentBytesonian.SetActive (true);
}
}
void Update()
{
if(!isLocalPlayer)
{
return;
}
//---------------BYTESONIANS----------------\
//Si las variables se quedan a 0 (es decir, todas las unidades estan instanciadas), borramos los botones
if( StructManager.VG.unidadBasicaBS == 0 && StructManager.VG.unidadPesadaBS == 0 &&
StructManager.VG.unidadMeleeBS == 0 && StructManager.VG.unidadVehicleBS == 0 &&
StructManager.VG.unidadGeneralBS == 0)
{
Destroy (buttonBasicBS);
Destroy (buttonHeavyBS);
Destroy (buttonVehicleBS);
Destroy (buttonMeleeBS);
Destroy (buttonGeneralBS);
}
//--------------HOMINIS SOLARIS--------------\
//Si las variables se quedan a 0 (es decir, todas las unidades estan instanciadas), borramos los botones
if( StructManager.VG.unidadBasicaHS == 0 && StructManager.VG.unidadPesadaHS == 0 &&
StructManager.VG.unidadMeleeHS == 0 && StructManager.VG.unidadVehicleOFHS == 0 &&
StructManager.VG.unidadVehicleTRHS == 0 && StructManager.VG.unidadGeneralHS == 0)
{
Destroy (buttonBasicHS);
Destroy (buttonHeavyHS);
Destroy (buttonVehicleOFHS);
Destroy (buttonVehicleTRHS);
Destroy (buttonMeleeHS);
Destroy (buttonGeneralHS);
}
}
public void SelectBoton(string accion)
{
switch (accion)
{
//Bytesonians
case "BASICAB": CmdBB (); break;
case "HEAVYB": CmdHB (); break;
case "MELEEB": CmdMB (); break;
case "VEHICLEB": CmdVB (); break;
case "GENERALB": CmdGB (); break;
//Hominis
case "BASICAHS": CmdBHS (); break;
case "HEAVYHS": CmdHHS (); break;
case "MELEEHS": CmdMHS (); break;
case "VEHICLEOFHS": CmdVOFHS (); break;
case "VEHICLETRHS": CmdVTRHS (); break;
case "GENERALHS": CmdGHS (); 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);
}
}
[Command]
void CmdHB()
{
if (StructManager.VG.unidadPesadaBS > 0)
{
//Instanciamos
GameObject newUPesadaBS = Instantiate (unitatHeavyBS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadPesadaBS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUPesadaBS;
if(StructManager.VG.unidadPesadaBS <= 0)
{
buttonHeavyBS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUPesadaBS);
}
}
[Command]
void CmdMB()
{
if (StructManager.VG.unidadMeleeBS > 0)
{
//Instanciamos
GameObject newUMeleeBS = Instantiate (unitatMeleeBS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadMeleeBS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUMeleeBS;
if(StructManager.VG.unidadMeleeBS <= 0)
{
buttonMeleeBS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUMeleeBS);
}
}
[Command]
void CmdVB()
{
if (StructManager.VG.unidadVehicleBS > 0)
{
//Instanciamos
GameObject newUVehicleBS = Instantiate (unitatVehicleBS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadVehicleBS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUVehicleBS;
if(StructManager.VG.unidadVehicleBS <= 0)
{
buttonVehicleBS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUVehicleBS);
}
}
[Command]
void CmdGB()
{
if (StructManager.VG.unidadGeneralBS > 0)
{
//Instanciamos
GameObject newUGeneralBS = Instantiate (unitatGeneralBS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadGeneralBS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUGeneralBS;
if(StructManager.VG.unidadGeneralBS <= 0)
{
buttonGeneralBS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUGeneralBS);
}
}
//---------------------HOMINIS SOLARIS---------------------\
[Command]
void CmdBHS()
{
//Si el numero de unidades seleccionadas es mayor o igual a 0...
if (StructManager.VG.unidadBasicaHS > 0)
{
//Instanciamos
GameObject newUBasicHS = Instantiate (unitatBasicHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadBasicaHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUBasicHS;
if(StructManager.VG.unidadBasicaHS <= 0)
{
buttonBasicHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUBasicHS);
}
}
[Command]
void CmdHHS()
{
if (StructManager.VG.unidadPesadaHS > 0)
{
//Instanciamos
GameObject newUPesadaHS = Instantiate (unitatHeavyHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadPesadaHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUPesadaHS;
if(StructManager.VG.unidadPesadaHS <= 0)
{
buttonHeavyHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUPesadaHS);
}
}
[Command]
void CmdMHS()
{
if (StructManager.VG.unidadMeleeHS > 0)
{
//Instanciamos
GameObject newUMeleeHS = Instantiate (unitatMeleeHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadMeleeHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUMeleeHS;
if(StructManager.VG.unidadMeleeBS <= 0)
{
buttonMeleeHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUMeleeHS);
}
}
[Command]
void CmdVOFHS()
{
if (StructManager.VG.unidadVehicleOFHS > 0)
{
//Instanciamos
GameObject newUVehicleOFHS = Instantiate (unitatVehicleOFHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadVehicleOFHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUVehicleOFHS;
if(StructManager.VG.unidadVehicleOFHS <= 0)
{
buttonVehicleOFHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUVehicleOFHS);
}
}
[Command]
void CmdVTRHS()
{
if (StructManager.VG.unidadVehicleTRHS > 0)
{
//Instanciamos
GameObject newUVehicleTRHS = Instantiate (unitatVehicleTRHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadVehicleTRHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUVehicleTRHS;
if(StructManager.VG.unidadVehicleTRHS <= 0)
{
buttonVehicleTRHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUVehicleTRHS);
}
}
[Command]
void CmdGHS()
{
if (StructManager.VG.unidadGeneralHS > 0)
{
//Instanciamos
GameObject newUGeneralHS = Instantiate (unitatGeneralHS, mousePosition, Quaternion.identity) as GameObject;
StructManager.VG.unidadGeneralHS--; //Restamos 1 a las unidades seleccionadas
RayCastRatoli.instance.unitat = newUGeneralHS;
if(StructManager.VG.unidadGeneralHS <= 0)
{
buttonGeneralHS.GetComponent<Button> ().interactable = false;
}
NetworkServer.Spawn(newUGeneralHS);
}
}
}