Quantcast
Channel: Latest Questions by Jack-Does
Viewing all articles
Browse latest Browse all 5

How to handle local arrays in unet?

$
0
0
I am working on my first multiplayer game and having trouble with an list of gameobjects. Each player has 2 preset arrays of game objects. when they start, each player chooses their team and an empty list is filled with the corresponding preset array objects. The problem is that only the host is able to fill the empty list while the client just twiddles their thumbs. Nothing should need to be sent over the network sense all the players have both preset arrays built in from the get-go. public List selectedArmy; public GameObject[] armyRed; public GameObject[] armyBlue; void Update(){ if (!isLocalPlayer) { return; } if (!armySelected) { if(Input.GetKeyUp(KeyCode.R)){ foreach(GameObject go in armyRed){ selectedArmy.Add (go); } armySelected = true; } else if (Input.GetKeyUp(KeyCode.B)){ foreach(GameObject go in armyBlue){ selectedArmy.Add (go); } armySelected = true; } } // if(isTurn){ if(Input.GetKeyUp(KeyCode.Q)){ CmdSpawnModel (0); } if(Input.GetKeyUp(KeyCode.E)){ CmdSpawnModel (1); } // } } [Command] public void CmdSpawnModel(int _unitToSpawn){ GameObject _newUnit = (GameObject)Instantiate (selectedArmy[_unitToSpawn], new Vector3(0,0,0), transform.rotation); NetworkServer.Spawn (_newUnit); } All I get from the client is an error saying that the array index is out of range. The host handles everything fine. I am new to networking so maybe I'm just overlooking something simple. Any help is greatly appreciated. P.S. everything has networkidentity, is added to networkmanagers registered prefabs. And if i change the code to not use arrays everything works.

Viewing all articles
Browse latest Browse all 5

Latest Images

Trending Articles





Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>
<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596344.js" async> </script>