Network inferno : how to tell a spawned player that it has to defend a gameobject already in the scene ?
Hi everyone, I’ve been searching for hours in the forum and watched a bunch of tutorials, but I don’t find how to do what I want.
(I’m not fluent in english, please excuse any mistake !;-).
I’ve a very simple game for 2 players that works really nice in « solo » mode (versus an AI computer). Now, I’m trying to make this same game work with 2 players (2 humans versus). So I started to work with the network solution built in Unity. I use the free LobbyManager asset. Works fine to match game instances.
But, every time I see a tuto or an documentation, the player example is always defending himself. That’s frustrating ! My problem is :
How to tell the « spawned players » which object, already existing in the scene, they have to protect. (« Host gamer you are at position A and must protect existing Weakpoint A », "Client gamer you are at position B and must protect existing Weakpoint B" ) ?
This is in order to make the weakpoint X be able to tell the player X « hey boss, I’m hurt, take Damage ! ». It already works fine in the non-network version (myProtector.TakeDamage(int x)). But, in the network mode, I can not figure a way to associate a pre-existing WeakPoint gameObject to a spawned player (and vice-versa).
I’ve tried so much ways ! The last fail : make a parent containing the weakpoint & the player (so the Weakpoint (child(0)) can know that it’s protector is transform.parent.getChild(1)), but when the Network Manager automatically spawns the entire group, the player SyncVar does not work anymore, neither the Sync Transform (I think because the player is then a child object in this case).
Any little help, even on a small parts, would be a big step for me. (I’m working with C# freshly learned). And if I’m misunderstanding a concept, please tell me :).
Thank you. Cédric.
Answer by PiFLYON · Nov 30, 2016 at 08:32 AM
After a while after having almost given up the multiplayer mode, I got back to it and found a solution, I use the position of the player to know which side of play scene he is. Then I give him a parent containing the differents elements needed (life bar, weak point). Then I define in the player script these elements getting the other children.
As I use the Network Lobby manager with the Round Robin method and StartPositions, I would have prefered to really have the name of the startPosition gameObject instead of checking player's position (if Z<0 he is in the front side, and if Z>0 in the back). But I did not find anyone saying how to do that.
(Now I'm stuck with the Lobby Manager : I did find how to go back to it after Game Over, but I don't find how to go back to leave the Lobby Manager and go back to main menu... I'll ask for another question in the forum).
Your answer
Follow this Question
Related Questions
Unet gameobject activete & deactivete 0 Answers
i just can't seem to figure out how to make a voting system, using SyncVar hooks and commands 0 Answers
Exiting a UNET lobby causes future ClientRPC calls to be ignored. 1 Answer
i just can't seem to figure out how to make a voting system, using SyncVar hooks and commands 0 Answers
[Multiplayer] How to invite friends to a lobby game? 0 Answers