- Home /
Question by
Ivanovic27 · Apr 21, 2017 at 05:00 PM ·
2d gamespawnmultiplayer-networking
Unity 2D Multiplayer Spawning
Hello, We've been trying to develop Unity 2D Multiplayer for our game, a player prefab is spawned not an object and we want to spawn stuff from an object to other. We always get messagges such as "Trying to send command for object without authority" and SpawnObject (Clone) Network is not active. Here is the code we are using:
void Update()
{
if(Input.GetKeyDown(KeyCode.Space))
{
if(isServer)
{
RpcAttack(GameObject.FindGameObjectWithTag("test"));
}
else
{
CmdAtacar(GameObject.FindGameObjectWithTag("test"));
}
}
}
[ClientRpc]
void RpcAttack(GameObject celulaAtacar)
{
if (selectedCells.Count > 0)
{
foreach (var selectedCell in selectedCells)
{
if (selectedCell == celulaAtacar)
{
return;
}
}
foreach (var celula in selectedCells)
{
var celulita = GameObject.Instantiate(celulaHija, celula.position, celula.rotation);
objNetId = celulita.GetComponent<NetworkIdentity>();
celulita.GetComponent<CelulaHija>().blanco = celulaAtacar.transform;
celulita.GetComponent<CelulaHija>().celulaPadre = celula;
celulita.GetComponent<CelulaHija>().CmdHacer();
celula.GetComponent<Cell>().poder /= 2;
NetworkServer.SpawnWithClientAuthority(celulita,connectionToClient);
}
borrarSeleccion();
}
}
[Command]
void CmdAtacar(GameObject celulaAtacar)
{
RpcAttack(celulaAtacar);
}
We already use Network.Spawn(); with the same result. Our Object to spawn does appear on the host and client but the client can only see its object on their screen but they won't appear on the host. Any idea why this is happening?
Comment