Hi Guys, right now I am making a 1v1 LAN space shooter game. I am trying to program something so that when the local player’s health is zero, a “You Lose” message shows up (easy). However, I also want a “You Win” message to show up if the other player’s health is zero. To do this, I need to check the other player’s health variable, which I am not sure how to do. I have searched google but nothing is coming up. Please tell me how to do this, thanks.
It depends a bit on your setup but lets assume you are using the standard approach where you definitely have a server (that can also be a client). No matter the details though, in this case, you never want two clients to communicate directly with each other. Instead you run everything through the server.
If one client dies, send a [Command] to the server with all the info you’d like to share. The server then updates its player list and this is also where you want to check which player is a winner and which one is a loser. Each client then gets a rpc call informing him of the changes the server just made.
It’s a fairly basic problem so I recommend studying this source:
https://docs.unity3d.com/Manual/UNetUsingHLAPI.html
There are tons of examples that should make things more clear