Search Unity

after user logs in i need to display their username

Discussion in 'Scripting' started by magstorey, Mar 21, 2019.

  1. magstorey

    magstorey

    Joined:
    Feb 20, 2019
    Posts:
    13
    Hi all,
    so i have created the login and register scenes and they work perfectly (i think) checking mySql db and inserting.
    when the main menu scene loads after login or reg i want to display their username. how would i go about this?
     
  2. Hosnkobf

    Hosnkobf

    Joined:
    Aug 23, 2016
    Posts:
    1,096
    Is it about how to display text?
    Here there are a lot of possible ways. I would recommend TextMesh Pro. And because it sounds like a UI I would use the TextMesh Pro UGUI component.

    Or change the text of a label?
    It depends what you are using. If you use TextMesh Pro, you just need to get the component and assign the username to the text property.

    Or don't you know how to get the username?
    Actually you should be able to know it. You logged in with it, right? So, you can store it in a variable when you send the login request.
    Alternatively, you could also include the user name in the response of the server.

    I hope I answered your question. If not, please specify it more clearly.
     
  3. magstorey

    magstorey

    Joined:
    Feb 20, 2019
    Posts:
    13
    at the moment i cant show code or screens but ill try to be as clear as i can.
    i have a scene where a user either logs in or register, in the next scene is the main menu. i want to be able to have a welcome <username~> type thing.

    im not sure how to carry the logged in username over.
    do i store it in a session variable in the php or use dont destroy on load?

    cheers
     
  4. Brathnann

    Brathnann

    Joined:
    Aug 12, 2014
    Posts:
    7,188
    Just have an account data script (doesn't have to inherit from monobehaviour, but it can if you want) with a static variable userName and store the value there. Then you can get the value from anywhere.

    It's perfectly fine to use a static variable for this. I use this sort of setup for stuff I know isn't going to change but I may use throughout.