I am trying to have the localplayer tell the server to spawn a prefab and network it to all players. The prefab has network identity on it. My issue is the prefab wont spawn on the client (works as intended on the host/server). The script controlling the prefab spawning is as follows.
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class SnowpileController : NetworkBehaviour {
public float spawnTime;
private float nextTime;
// private GameObject[] powerupArray;
public GameObject snowPile;
// Use this for initialization
void Start()
{
nextTime = Time.time+5;
CmdSnowballSpawn();
}
// Update is called once per frame
void Update()
{
if (Time.time > nextTime)
{
nextTime = nextTime + spawnTime;
Debug.Log("trying to spawn");
CmdSnowballSpawn();
}
}
[ClientRpc]
void RpcSnowballSpawn()
{
CmdSnowballSpawn();
}
[Command]
void CmdSnowballSpawn()
{
var objs = FindObjectsOfType<SnowpileSpawn>();
var spawnPos = objs[Random.Range(0, objs.Length)];
var randX = Random.Range(0.0f, 1.0f);
var randY = Random.Range(0.0f, 1.0f);
var bullet = (GameObject)Instantiate(
snowPile,
spawnPos.transform.position + (new Vector3(randX, randY, spawnPos.transform.position.z)),
spawnPos.transform.rotation);
NetworkServer.Spawn(bullet);
}
}