Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Inputfield/Username view

Discussion in 'Scripting' started by ZimonIsHim, Apr 18, 2015.

  1. ZimonIsHim

    ZimonIsHim

    Joined:
    Apr 18, 2015
    Posts:
    7
    I have a scene with an inputfield and one button (The menu) and I have an other scene (The game)
    I want the text of the inputfield on this position (In the second scene):

    function OnGUI(){
    GUI.Label(Rect(10, 20, 500, 500), ""+username); //username is the inputfield btw
    }

    Does someone know how to code this?
    And where do i put the code if i need a other place than the camera?
     
  2. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    There are multiple ways to achieve that.

    You could, for example, have a script in the first scene which will store the value of the input field and have a "DontDestroyOnLoad" somewhere in its code.

    When you will load the second scene, the script holding the username will still be there (due to DontDestroyOnLoad) and you will be able to access it in any way you want.

    But again, this will depend on what you actually want to achieve. There are many ways of doing it, this is just one of them :)