- Home /
Question by
PvTGreg · Jul 23, 2016 at 01:15 PM ·
c#networking
[Command] only working on host
Hi im trying to share a list over network but it only seams to work on the host
i call this when i die
[Command]
void CmdSpawnBody(){
GameObject body = (GameObject)Instantiate (DeathObject);
body.transform.position = new Vector3 (this.transform.position.x,this.transform.position.y,0.01f);
NetworkServer.Spawn (body);
for(int i = 0;i < GetComponent<Inventory>().inventory.Count;i++){
body.transform.GetComponent<Container> ().CmdUpdateItems (
GetComponent<Inventory> ().inventory [i].ItemName
,GetComponent<Inventory> ().inventory [i].ItemID
,GetComponent<Inventory> ().inventory [i].ItemAmount
,GetComponent<Inventory> ().inventory [i].itemType
,GetComponent<Inventory> ().inventory [i].Sprite
,GetComponent<Inventory> ().inventory [i].Stackable
,i);
}
}
which accesses this funtion on the body object
[Command]
public void CmdUpdateItems(string name,int id,int amount,string type,string sprite,bool stack, int place){
container.Add (new ContainerItem());
container [place].ItemName = name;
container [place].ItemID = id;
container [place].ItemAmount = amount;
container [place].itemType = type;
container [place].Sprite = sprite;
container [place].Stackable = stack;
}
why does this only work on the host. when another player dies the list isnt added to. am i doing something wrong?
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612085355im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Why the Network Health script is always null 0 Answers
Command method dont change variables on server 0 Answers
Understanding Unet attributes 2 Answers