Search Unity

Player name in multiplayer game big problem

Discussion in 'Scripting' started by wisien92, Feb 28, 2014.

  1. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    Hi i have problem with player name in multiplayer game. In network manager when spawning i set player name in playerdata script and then i want to get string from that script and put it into 3dText. Unfortunetly the 3dText text is empty when getting data from that script.... i have no idea how to achieve that. Parts of my scripts:

    spawn in network manager
    Code (csharp):
    1.  
    2. void SpawnMyPlayer() {
    3.         AddChatMessage("Spawning player: " + PhotonNetwork.player.name);
    4.  
    5.         playerName = PhotonNetwork.player.name;
    6.  
    7.         SpawnSpot mySpawnSpot = spawnSpots[ Random.Range (0, spawnSpots.Length) ];
    8.         GameObject myPlayerGO = (GameObject)PhotonNetwork.Instantiate("PlayerController", mySpawnSpot.transform.position, mySpawnSpot.transform.rotation, 0);
    9.         standbyCamera.SetActive(false);
    10.  
    11.         ((MonoBehaviour)myPlayerGO.GetComponent("BetaMovement")).enabled = true;
    12.         myPlayerGO.GetComponent<PlayerData> ().playerName = PhotonNetwork.player.name.ToString ();
    13.                 ............................
    14.     }
    15.  
    update in player data

    when i comment this line the text set in editor is displayed
    Code (csharp):
    1.  
    2. void Update () {
    3.         transform.FindChild ("Name").GetComponent<TextMesh> ().text = playerName;
    4.     }
    5.  
     
    Last edited: Mar 1, 2014
  2. wisien92

    wisien92

    Joined:
    Nov 16, 2012
    Posts:
    56
    anyone any idea?