Search Unity

Score board and assigning player ID's myself

Discussion in 'Multiplayer' started by Owlzy, Sep 26, 2014.

  1. Owlzy

    Owlzy

    Joined:
    Jul 7, 2014
    Posts:
    3
    Hullo,

    I am having real problems working out how to assign the players a simple int ID.

    In the start function I want the server to send an RPC to each player individually giving it a number 0, 1, 2 ...... connections.length

    Server already has an array of player class, and the ID from the RPC I want to use as the index of the array.

    Code (JavaScript):
    1. function Start () {
    2.  
    3.     if (Network.isServer) {
    4.    
    5.         playerLength = Network.connections.Length - 1;
    6.         playerArray = new Player[playerLength];
    7.         networkView.RPC("SendPlayerLength", RPCMode.Others, playerLength);
    8.         //can deal with giving network ids here.  for i < playerlength { send rpc(networkid, i);
    9.  
    10.     }
    Player class
    Code (JavaScript):
    1. class PlayerStruct extends System.ValueType{
    2.  
    3.     var _myName : int;
    4.     var _myScore : int;  
    5.    
    6.     //probably need another struct here, for hole number, score, par.  or a 2d array may be easier
    7.  
    8. }
    All clients are already joined and ready to play when this script is started, and there are no late joiners as this is a mini golf game.