Search Unity

  1. Unity 2019.1 beta is now available.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. We're looking for insight from anyone who has experience with game testing to help us better Unity. Take our survey here. If chosen to participate you'll be entered into a sweepstake to win an Amazon gift card.
    Dismiss Notice
  4. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  5. Unity 2018.3 is now released.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

How to make my Login System networkable?

Discussion in 'Scripting' started by itzcrazyzockt, Dec 7, 2018.

  1. itzcrazyzockt

    itzcrazyzockt

    Joined:
    Dec 7, 2018
    Posts:
    5
    im new to networking in Unity and at the moment im trying to forge my Login System together with a multiplayer test. I logged into two different Accounts (tesuser & Funex - mirrored in the picture below, just ignore it) and let them join on one server. But as you can see in the picture below they have the same name on each build. (Blue marks the Local player on every build). In the code you can see the script that sets the username and kills Text for every player. (DBManager.username and DBManager.kills are the variables that are connected to my online database). Do i have to add something in order to make it work?

    Cheers Screenshot_2.png Screenshot_3.png
     
  2. qaisAhm

    qaisAhm

    Joined:
    Nov 21, 2015
    Posts:
    9
    Look into NetworkBehaviours, they have the same features as MonoBehaviours but add lots of networking features. Your code doesnt check if its the local client so they run on all your clients thats why you end up with the same name on both. If you want the name change to only happen on the local client you need to check for IfIsLocalPlayer before setting the name or moving it.

    You can find more info on IfIsLocalPlayer here >> https://docs.unity3d.com/ScriptReference/Networking.NetworkBehaviour-isLocalPlayer.html
     
  3. itzcrazyzockt

    itzcrazyzockt

    Joined:
    Dec 7, 2018
    Posts:
    5
    I already used if(islocalplayer) in another script so ill test it out as soon as im home, thanks for your help :)