- Home /
Assigning Player Numbers
I'm going out of my mind trying to set a global array inside my network controller which assigns an integer to players when they join the game.
I've read so many docs and tutorials about networking and RPCs that my head hurts. Clearly networking isn't for me; but I still need to get this working so I can [finally] continue.
What I want to do seems very simple to me: I have a single empty game object with my network manager script and a network view attached (state sync is set to 'off' and observed is 'none' because the data is being sent thru RPC calls). The network manager script handles all the player object instantiations as expected. When a player joins, I want the network manager to:
check an array which holds all the player slots,
find the first open slot,
then set the player object's player number (a public integer variable) to that open slot thru an RPC call,
and finally set that open slot to full, so players don't get instantiated as the same number.
Maybe it's my own frustration at failing so hard at this, but it blows my mind that I can't find an internal call to return the local player's player number as the int they were assigned when they joined. Just to illustrate: the player number will be referenced pretty frequently-- until I got stuck here, I was using the player numbers to set alliances:
if(localPlayerController.alliances[playerNumberOfTarget]==AllianceClassStatus.enemy)
//Allow Player to attack.
I hope I'm not letting my frustration seep into this post too much. And again, I apologize if I am missing an internal call that I can use, but I've read every doc I could find. I just can't wrap my head around networking, and I'll be very happy to get this tied down.
Edit:: And to clarify, I'm looking for a way to make an array of anything that I can reference later by the array index; such as
player[1]==<GameObject> or <NetworkPlayer> or <Network.IpAddress>, etc.
Your answer
Follow this Question
Related Questions
Target = NetworkedMe 1 Answer
Identifying local player issue 0 Answers
Send array of transforms via RPC. [C#] 1 Answer