Search Unity

How to add multiple player objects on one client

Discussion in 'Multiplayer' started by RkSanders, Jul 13, 2015.

  1. RkSanders

    RkSanders

    Joined:
    Jun 28, 2011
    Posts:
    26
    I'm creating a Commander class that is representative of the players connection to the host. I want to also add a Unit player object to the connection that will be the physical representation of the player. I can't figure out how this is supposed to be done. It looks like I should be able to add the Unit with NetworkServer.AddPlayerForConnection() but there's always an error with the playerControllerId. e.g. I can't seem to just: conn.playerControllers.Add() or pass conn.playerControllers.Count.

    I believe I need the Unit to be a player object because I need the NetworkIidentity.IsLocalPlayer true so NetworkTransform works.

    Anyone know how to do this? or the way it should be done?
     
  2. RkSanders

    RkSanders

    Joined:
    Jun 28, 2011
    Posts:
    26
    Was able to get this working with ClientScene.AddPlayer().

    NetworkManager.singleton.playerPrefab = GameManager.instance.unitPrefab;

    var conn = connectionToClient;
    ClientScene.AddPlayer((short)conn.playerControllers.Count);