Search Unity

Multiplayer Login Problem

Discussion in 'Scripting' started by Doomer022, Jul 5, 2018.

  1. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    I have a mutliplayer football game, and the players have 3D text meshes for username. I also created a simple login screen with an inputfield and a button. You just type in your name, click the button, and your username will be the one you just typed in. However, none of this happens. The script is in an empty game object. You can of course enter a name, but when the button is clicked, it wont go to the next scene, and it also wont set the "userNameLogin" string to the name you entered. I never worked with multiplayer games.

    The "LoginMenu" script:


    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using UnityEngine.UI;
    5. using UnityEngine.SceneManagement;
    6. using UnityEngine.Networking;
    7.  
    8. public class LoginMenu : NetworkBehaviour {
    9.  
    10.     public InputField nameField;
    11.     public string userNameLogin;
    12.     public Button loginButton;
    13.  
    14.     void OnSubmit()
    15.     {
    16.         userNameLogin = nameField.text.ToString();
    17.         SceneManager.LoadScene(1);
    18.     }
    19. }
    20.  
    Thank you! :)
     
  2. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    On your Build Settings, check if the scene 1 is added there.
    Also, when you say "t also wont set the "userNameLogin" string to the name you entered", what do you actually expect to happen in the game?
    Seems like the input field text value is being set to the string userNameLogin , but nothing else is being done with it.
    Also, if you don't store that value somewhere that won't be destroyed by the new scene you're going to lose the value.
     
  3. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    How it works, is that you enter something into the Inputfield, that will be your username, and then what you entered gets converted into a static string, and then its sent to the player's car's 3d text mesh, and the text on the text mesh will be the username string. The button will just pu the player to the next scene, the Lobby, which is multiplayer. And others should see this change in your name too.
     
    FernandoHC likes this.
  4. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    Ah ok cool, you could make userNameLogin itself be static then,and just fetch from there.
    Were you able to solve the issue for not going to the next scene? if not what happens?
     
  5. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Okay, i noticed another problem. The login manager gameobject that has this script turns off when testing. And no, it still doesnt work sadly. :( It also received a Network Identity script. What should I do wit that? And how do i put the stuff into the string from the inputfield then?
     
  6. FernandoHC

    FernandoHC

    Joined:
    Feb 6, 2018
    Posts:
    338
    You can define:
    public string userNameLogin; to be:
    public static string userNameLogin; instead.

    This way you can access it from anywhere in your code by calling LoginMenu userNameLogin.
    What do you mean by the gameobject turns off? does it get deactivated? If so, check on your code where and why.
    I'm afraid I don't know what you mean by network identity script.
    Also, keep an eye on the console to look for possible errors.
    We'd need more information and code to troubleshoot this further.
     
  7. Doomer022

    Doomer022

    Joined:
    May 16, 2018
    Posts:
    73
    Thank you! It worked flawlessly! Great! Now i just somehow have to make a script so I can see other player's name too, but ill make a different post for that

    Thanks again! :D