Search Unity

  1. Get all the Unite Berlin 2018 news on the blog.
    Dismiss Notice
  2. Unity 2018.2 has arrived! Read about it here.
    Dismiss Notice
  3. Improve your Unity skills with a certified instructor in a private, interactive classroom. Learn more.
    Dismiss Notice
  4. ARCore is out of developer preview! Read about it here.
    Dismiss Notice
  5. Magic Leap’s Lumin SDK Technical Preview for Unity lets you get started creating content for Magic Leap One™. Find more information on our blog!
    Dismiss Notice
  6. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Transferring Data between Lobby and Game Player Prefab?

Discussion in 'Connected Games' started by GVT017, Jul 10, 2018.

  1. GVT017

    GVT017

    Joined:
    May 16, 2018
    Posts:
    44
    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