- Home /
Question by
muzzammil-mahmud-sheikh · Mar 02, 2018 at 01:36 PM ·
networkingmultiplayermultiplayer networking
Unity Networking Client not calling functions on server
i have a 2 player game. I becomes a server the other a client.I am call the method "buttonclicked" from both the sides when they are connected.
When the method "buttonclicked" is called from the side which becomes the server, code executes well and an enemy is generated on both the side which is the server and the one which is the client.
However when the same code is run from the client the enemy is not generated on the side which becomes the server.
Below is the code
public void buttonclicked (int enemyID){
CmdgenerateEnemies (enemyID);
}
[Command]
public void CmdgenerateEnemies(int enemyID){
RpcgenerateEnemywithID(enemyID);
}
[ClientRpc]
public void RpcgenerateEnemywithID(int enemyID){
enemyID = 1; // hardcoded for testing
for (int i = 0; i < enemiesArray.Length; i++) {
GameObject enemy = enemiesArray [i];
if (enemy.GetComponent<EnemyScript> ().enemyId == enemyID) {
GameObject einstance = Instantiate (enemy, spawnPoint1);
einstance.transform.parent = canvas.transform;
einstance.GetComponent<splineMove> ().pathContainer = topPath[1];
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Is Unet too heavy for mobile games? 0 Answers
[UNET LLAPI] Appending data to disconnect events 0 Answers
How do you use SetDirtyBit ? 0 Answers