Exemplo n.º 1
0
    public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
    {
        Debug.Log("NetManager OnServerAddPlayer");
        Vector3          position   = Vector3.zero;
        Quaternion       rotation   = Quaternion.identity;
        PlayerSpawnPoint spawnPoint = PlayerSpawnPoint.Next();

        if (spawnPoint != null)
        {
            position = spawnPoint.position;
            rotation = spawnPoint.rotation;
        }

        //add player object
        GameObject     player   = (GameObject)GameObject.Instantiate(playerPrefab, position, rotation);
        PlayerIdentity identity = player.GetComponent <PlayerIdentity>();

        if (identity != null)
        {
            //TODO: player name and team id values are temporary - maybe grab from settings?
            string playerName = player.name + conn.connectionId.ToString();
            byte   teamId     = 1;
            identity.Initialize(conn.connectionId, playerControllerId, playerName, teamId);
        }
        else
        {
            Debug.LogWarning("NetManager: Player prefab does not have a PlayerIdentity assigned.");
        }
        m_playerTracker.Add(player);
        NetworkServer.AddPlayerForConnection(conn, player, playerControllerId);
    }