Example #1
0
    // here we created load and create player prefabs
    public void OnServerStarted(int num)
    {
        playerNum = num;
        players   = new List <Player>();
        float xPos = -Gameplay.xInterval * (num - 1) / 2.0f;

        for (int i = 0; i < num; ++i)
        {
            if (i == localPlayerID)             // local player
            {
                GameObject player = GameObject.Instantiate(Resources.Load("LocalPlayer", typeof(GameObject)), new Vector3(xPos, 0.5f, zPos), Quaternion.identity) as GameObject;
                localPlayer = player.GetComponent <LocalPlayer>();
                localPlayer.Init(i, zPos, Gameplay.serverTickInterval, rightButton, leftButton);
                players.Add(localPlayer);
            }
            else                 // remote player
            {
                GameObject   player       = GameObject.Instantiate(Resources.Load("RemotePlayer", typeof(GameObject)), new Vector3(xPos, 0.5f, zPos), Quaternion.identity) as GameObject;
                RemotePlayer remotePlayer = player.GetComponent <RemotePlayer>();
                remotePlayer.Init(i, zPos, Gameplay.serverTickInterval);
                players.Add(remotePlayer);
            }
            xPos += Gameplay.xInterval;
        }
    }
Example #2
0
    private void RegisterPlayer(User u)
    {
        User         user = u;
        GameObject   newRemotePlayerObj = Instantiate(remotePrefab, Vector2.zero, Quaternion.identity);
        RemotePlayer remotePlayer       = newRemotePlayerObj.AddComponent <RemotePlayer>();

        remotePlayer.Init(user.ID, user.Name, user.CharacteID);
        remotePlayers.Add(user.ID, remotePlayer);
    }