Search Unity

Pass player script component from client to server

Discussion in 'Multiplayer' started by safak93, Mar 22, 2018.

  1. safak93

    safak93

    Joined:
    Feb 23, 2014
    Posts:
    19
    Hi guys,

    I'm trying to pass the PlayerController script to the spawned bullet to determine the next turn after it hit something. Players are always a client and server is the gameserver that it hosted somewhere else.

    Playerscript has this command but it does not pass it:
    Code (CSharp):
    1.      CmdFireBullet(gameObject);
    2.    
    3.      [Command]
    4.      private void CmdFireBullet(GameObject _gameObject)
    5.      {
    6.          bullet = (GameObject) Instantiate(bulletprefab);
    7.          bullet.GetComponent<BulletController> ().AddPlayer (_gameObject.GetComponent<PlayerController>());
    8.          NetworkServer.Spawn (bullet);
    9.      
    Bulletscript (is owned by Server)
    Code (CSharp):
    1.      public List<PlayerController> playerList = new List<PlayerController>();
    2.    
    3.          public void AddPlayer(PlayerController pc)
    4.      {
    5.          playerList.Add(pc);
    6.      }
    However if the client acts as a server and I use this "ball.GetComponent ().AddPlayer (this);" in commad it passes on both side.

    Can anyone help me with this?