Search Unity

  1. If you have experience with import & exporting custom (.unitypackage) packages, please help complete a survey (open until May 15, 2024).
    Dismiss Notice
  2. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice

Transferring Data between Lobby and Game Player Prefab?

Discussion in 'Multiplayer' started by Doomer022, Jul 10, 2018.

  1. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    My usernames are STILL not working, and team colors dont get transferred from the lobby player prefab to the game player prefab. Please Answer!

    Lobby scene:
    - The host can see everyones username and colors
    - The clients can only see their own username and colors, sometimes. I dont think it gets updated as commonly as it should.

    Game scene:
    - Everyone sees everyone in their chosen color, everyone can see everyones name, but the host's name changes back to just the default "Username". Well thats something!

    Lobby:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class PlayerTeamManager : NetworkBehaviour {
    7.  
    8.     public Transform carLobbyTR;
    9.  
    10.     public GameObject carPlayer;
    11.  
    12.     public static string CarLobbyColor;
    13.  
    14.     public void OnCollisionEnter(Collision collision)
    15.     {
    16.         if (collision.gameObject.tag == "RedTeamPlatform")
    17.         {
    18.             this.GetComponent<MeshRenderer>().material.color = Color.red;
    19.             carPlayer.GetComponent<MeshRenderer>().material.color = Color.red;
    20.             CarLobbyColor = "Red";
    21.         }
    22.         if (collision.gameObject.tag == "BlueTeamPlatform")
    23.         {
    24.             this.GetComponent<MeshRenderer>().material.color = Color.blue;
    25.             carPlayer.GetComponent<MeshRenderer>().material.color = Color.blue;
    26.             CarLobbyColor = "Blue";
    27.         }
    28.     }
    29. }
    30.  
    Game:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.Networking;
    5.  
    6. public class PlayerTeamLobbyColorGet : NetworkBehaviour {
    7.  
    8.  
    9.     void Awake () {
    10.         if (PlayerTeamManager.CarLobbyColor == "Red")
    11.         {
    12.             this.GetComponent<MeshRenderer>().material.color = Color.red;
    13.         }
    14.         if (PlayerTeamManager.CarLobbyColor == "Blue")
    15.         {
    16.             this.GetComponent<MeshRenderer>().material.color = Color.blue;
    17.         }
    18.     }
    19. }
    20.  
    One more thing:

    I put this text here, because if i put it on the top, no one would answer the question because they would get hit by the hard truth.

    I dont think that this forum is too small to answer some SIMPLE UNet problems, and I dont think I really ever said something really rude to anyone. So? I dont know whats going on. I dont need assets, I dont need references and Unity Manual links, because Unity Manuals are trash in this situation. Just give me a code snippet or a SIMPLE easiliy understandable explanation! JUST PLEASE HELP! NOTHING ELSE! JUST HELP! Thank you!
     
    Last edited: Jul 10, 2018