Input player name to a variable

Hello,

I would like to create a GUI screen, which ask for the name of the player. The player would be able to input the choosen name, and then Unity would store it in a variable.

How can I archive this?

Use a GUI.TextField.

Here is a tutorial on how to use the Unity GUI system.

This is quite a broad question, but your script should create some GUI, you can read up on Unity GUI here:

http://unity3d.com/support/documentation/Components/GUI%20Scripting%20Guide.html

But many people use a GUI framework that saves time and draw calls, especially those of us developing for mobile!

I use EZUI which is excellent and comes with first class support:

http://www.anbsoft.com/middleware/ezgui/index.html

If you go the Unity GUI route then you would use a TextField, so something like:

void OnGUI()
{
   m_player_name = GUI.TextField (Rect (25, 25, 100, 30), m_player_name);
}

Should do the trick. What you ultimately do with the player name or where you store it, is kind of up to you and quite a wide question to answer - it depends on where you want to store things generally - it could be, for instance, a static public member on a Player class…