- Home /
how to send a command to a server only script
I have a enemy wave spawner that instantiates players on the network in waves. when all enemies in the wave are killed it starts another wave.
I'm trying to convert this script to a Networked version. However I can't find the proper way to subtract from the integer that holds how many enemies are left in the wave.
I have the spawning script attached to a Server-Only object. This way it will spawn the enemies on all clients only once without having multiple spawning scripts for each client, that are spawning their own zombies. however sense the object is only on the server I cannot find a way to reference it on the enemy script to subtract the enemies-left-in-wave integer in the spawning script.
so I am trying to send a command to a script that has a server only network identity attached to it. is this possible? if not is there another way to achieve this spawning system?
Answer by DiegoSLTS · Aug 26, 2016 at 09:39 PM
The server should be the only one that decides that an enemy was killed, not the clients. With that in mind, you don't need to call a Command, you should be able to get the spawner instance on the server. If draging doesn't work you can probably assign that reference after instantiating the enemy.
If you still want to let a client kill an enemy and tell the server, you can call Command on the local player object and since that Command runs on the server the spawner should be there.
Your answer
![](https://koobas.hobune.stream/wayback/20220612091553im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
UNET Buying/changing weapons ingame by players 0 Answers
My wave system isn't working 0 Answers
[URGENT] Problem with synchronizing objects loaded from server for multiplayer 0 Answers
Clients can't spawn bullets, but the server does 1 Answer
[Command] and [ClientRpc] works, but not the way they're supposed to ? 2 Answers