- Home /
How to use OnTriggerEnter and OnTriggerExit in multiplayer game
Hi. I'm making a multiplayer game and trying to reduce towers health when player enters in the area. When player enters in, the client will send a message to server, and server will tell both two clients to call the function "ReduceTowerHealth".
That's OK. But it will work only for one time. How can I make it continue ? If I send message everytime player stays in the tower area, it would get so much slower.
Answer by oomeroo1999 · Jul 03, 2019 at 11:33 AM
I solved it. When player1 enters in Tower2, the server will tell the clients to make a boolean true. And in Update, if boolean is true, towers health will reduce.
When player1 exits from tower2, the server will tell the clients to make the boolean false. And the function in Update will not execute.
Are not your tower synced? It should be if its an element that has shared behaviour for all your players,
Something like this example
That example is from version 2018.2 and I'm using 2019.3 because UNET is deprecated and we will not be able to use it soon. So there is no NetworkBehaviour anymore. I'm using LLAPI now.
Your answer