- Home /
Unity 5.1 network spawn doesn't work
Hi i am using the latest unity version 5.1.1 f1 and i have been stuck for ages trying to solve a problem which seems to be simple to everyone
i can't spawn objects to the server no matter what, this is the code
using UnityEngine;
using System.Collections;
using UnityEngine.Networking;
public class InsTest : NetworkBehaviour {
public GameObject testIns;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.I))
{
CmdTestIns();
}
}
[Command]
void CmdTestIns()
{
GameObject tmp = Instantiate(testIns,Vector3.zero,Quaternion.identity) as GameObject;
NetworkServer.Spawn(tmp);
}
}
its pretty simple and neat
i have all the components net manager and network identity and i have add the object to the spawn list
on this object that has this script there is only network identity i have debugged it outside the game and inside and they all run
first if i was the host the object gets instantiated but only one can see it which is the host
second if i was the client nothing gets instantiated on the host or the client
i have followed the steps very carefully of many tutorials on youtube and unity fourm/answers this bug just refuses to get solved
Answer by LiOn0X0HeaRt · Jun 24, 2015 at 10:55 AM
Solved it
unity doesn't work like photon you can't disable scripts and enable them when you want them to work only locally you should use IsLocalPlayer instead of disabling and enabling
Your answer
