Hi everyone, I’m new to Unity networking code. I’m just trying to get a prefab to spawn for all clients. My code is below. This script is attached to an empty gameObject in the scene. The issue I’m having is that the “baby” prefab is only spawning for the host, but not the connecting client. I’m running on localhost (Run and Build [Host] + Editor Play [Client]). Line #33 and #34 never seem to run and I don’t get a “Here3” message in the console (line #33). Line #26 appears to correctly spawn a baby but only for the hosting client, not the connecting client. Am I missing something simple? Any help is appreciated. The Network Identity component is not set to “Server Only” or “Local Player Authority”, both unchecked.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Networking;
public class BabyMaker : NetworkBehaviour {
public GameObject baby;
void Start ()
{
Debug.Log("Here1");
CmdbabyMaker(new Vector3(0, 2, 0));
}
void Update ()
{
}
[Command]
public void CmdbabyMaker(Vector3 pos)
{
Debug.Log("Here2");
Instantiate(baby, new Vector3(0, 2, 0), transform.rotation);
RpcbabyMaker();
}
[ClientRpc]
public void RpcbabyMaker()
{
Debug.Log("Here3");
Instantiate(baby, new Vector3(0, 2, 0), transform.rotation);
}
}