Why is the following code not spawning objects on both host and remote clients? How can I modify this code to make objects spawn on both host and remote clients? Is there a better solution?
using UnityEngine;
using UnityEngine.Networking;
public class CatSpawner : NetworkBehaviour
{
public int numberOfCats;
public GameObject catPrefab;
public override void OnStartServer()
{
for (int i = 0; i < numberOfCats; i++)
{
var spawnPosition = new Vector3(
Random.Range(-64.0f, 100.0f),
106.0f,
Random.Range(34.0f, 184.0f));
var spawnRotation = Quaternion.Euler(
0.0f,
Random.Range(0, 180),
0.0f);
var cats = (GameObject)Instantiate(catPrefab, spawnPosition, spawnRotation);
NetworkServer.Spawn(cats);
}
}
}
My object Prefab has Network Identity and Network Transform component. The Game Object with the spawning script has Network Identity. I don’t see the problem.