- Home /
How to implement "Owner" (as in P1 or P2)?
I'm working on a 1v1 online game and being my first multiplayer and first online game, I'm not really sure the best way to mark which base is which, which units, etc are owned by player 1 and by player 2. For example the player should be able to buy units when they click on their own base but not the opponent's base. Should I put all the units and buildings owned by player 1 in a Layer called Player 1 Owned, put them with a Tag, use a script variable (bool or enum), or what? I'm just not sure what the best way would be
The player needs to be able to select his own base, select his own units, and attack enemy units. Those are the 3 key reasons I need to differentiate between owning player
Answer by Kiwasi · May 27, 2014 at 12:32 AM
All of your methods mentioned will work. It depends what else you are using.
Tags is probably the easiest, but remember a GameObject can only have one tag. So if you rely on tags to identify ownership you can't use them for anything else. But see this
Layers could also work. However you run into the same problem with each GameObject only having one layer.
Script variables work, but will require you to place a script on each GameObject. There are multiple options to choose from here too.
Create a enum that keeps track of the owner
Create a GameObject that represents the owner and store a reference to the owner on each script
I think one of the main thing I'm having trouble wrapping my head around is whether I should be in ONE scene or one per player. Surely both players will be in the same singular scene when they play the match right? But then how can I code fog of war/vision for each player that the other can not see?
Also, thank you very much for your help :)
$$anonymous$$ulti player and networking is a complex topic. I have never attempted it myself.
Typically both players will work in separate but identical scenes generated on the local machine. The only data shared between them is when something changes.
this is what i needed to know, thanks! Now I can start putting it together knowing its 2 separate scenes :)
Your answer
Follow this Question
Related Questions
Php Character list/sessions 0 Answers
Multiple player spawnpoints 0 Answers
Network multiplayer chess/battleship game cameras 2 Answers
Entering multiple variables into a function 1 Answer
Changing to online sceen in multiplayer 0 Answers