- Home /
Question by
ScurvyJack · Mar 18, 2018 at 02:14 AM ·
networkingspawnspawning problemsnetwork.instantiatespawn-when-click
SpawnWithCLientAuthority Issues...
I have a script that spawns out soldiers.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class SoldierSpawner : NetworkBehaviour {
[SyncVar]
public int connectionId;
public float spawnTime = 5f;
//The amount of time between each spawn.
public float spawnDelay = 3f;
//The amount of time before spawning starts.
public GameObject soldier;
private void Start()
{
Debug.Log(connectionId);
Debug.Log(connectionToClient);
Debug.Log(connectionToServer);
Debug.Log(base.connectionToClient);
}
void Update()
{
if (hasAuthority)
{
if (Input.GetKeyDown(KeyCode.Space))
{
CmdShoot();
}
}
}
[Command]
void CmdShoot()
{
GameObject g = Instantiate(soldier, transform.position, transform.rotation) as GameObject;
NetworkServer.SpawnWithClientAuthority(g, base.connectionToClient);
}
}
everything works perfectly, except only the host has authority over the soldiers ie any unit that the host or any connected client spawns the host can control, the connected clients can spawn the units but have no control over them, I for the life of me cannot figure out how or why this is happening I feel like it should be simple....
Comment
Your answer
Follow this Question
Related Questions
UNET - Server is spawned in correct spawn position but players are spawned "half way" 0 Answers
Network player duplicated when replacing player with a new one 1 Answer
Scripts are being disabled during game play 0 Answers
Why will the raycast not work on the client? 2 Answers
Networking | Getting buffered other - previous spawned players 1 Answer