void CmdBroadcastDataFromAllCrew() { GameObject[] allCrew = GameObject.FindGameObjectsWithTag("PlayerCrew"); for (int i = 0; i < allCrew.Length; i++) { // access this PlayerCrew's data from server, propogate to all clients // broadcast references again PlayerCrew currentCrewScriptRef = allCrew[i].GetComponent <PlayerCrew>(); currentCrewScriptRef.setPlayerReferences(currentCrewScriptRef.ownerId, currentCrewScriptRef.myShipId); // broadcast some ship info ShipMovement shipScriptRef = currentCrewScriptRef.playerShipRef.GetComponent <ShipMovement>(); shipScriptRef.setPilotSeatOccupied(shipScriptRef.pilotSeatOccupied); } }
void CmdCreatePlayerOnShip(int shipNum) { string findShip = shipName(shipNum); myShipNum = (short)shipNum; Debug.Log("Joining ship: " + findShip); // Spawn this client's playerCrew on all clients // Set crew on the correct ship // set back and forth references between owner and crew on ALL clients myCrew = Instantiate(playerCrewPrefab); PlayerCrew crewScriptRef = myCrew.GetComponent <PlayerCrew>(); //crewScriptRef.ownerId = netId.Value; //crewScriptRef.myShipId = shipNum; //myCrew.GetComponent<PlayerCrew>().setOwnerRef(netId.Value); NetworkServer.SpawnWithClientAuthority(myCrew, connectionToClient); // give authority over spawned object to the client that called this command crewScriptRef.setPlayerReferences(netId.Value, shipNum); // current function body is on the server, therefore this line will execute only on server }