clear textfield from default string

Hi there,
I have a GUI.TextField with a default value “Name”. When the player activates the text field when it still contains the default value, I want it to be cleared.

This is what I tried but the problem is that, when it contains the default value, you have to click twice in order to enter text.

		//draw the name input field for the player
		if(Players*.name=="Name")*
  •   	{*
    
  •   	//if the name is still the default name, clear it*
    

_ if(GUI.Button(Rect (topLeft.x+40, topLeft.y+logo.height+i*playerItemHeight, 220, playerItemHeight),“”,invisible))_

  •   		{*
    

_ Players*.name=“”;_
_
}_
_
}_
Players_.name=GUI.TextField(Rect (topLeft.x+40, topLeft.y+logo.height+iplayerItemHeight, 220, playerItemHeight), Players*.name,11,listName);*_

Another variant to do this is to use GUI.SetNextControlName and GUI.GetNameOfFocusedControl:

public class Test : MonoBehaviour
{
private string _default = "name";
private string _player_name = "";

private void OnGUI()
{
	GUI.SetNextControlName ("player_name");
    _player_name = GUI.TextField(new Rect(0, 0, 200, 30), _player_name);

    if (UnityEngine.Event.current.type == EventType.Repaint)
    {
        if (GUI.GetNameOfFocusedControl () == "player_name")
        {
            if (_player_name == _default) _player_name = "";
        }
        else
        {
            if (_player_name == "") _player_name = _default;
        }
    }
}
}

Maybe you can do so:
Add tooltip (for example “name_text_field”) to text field. Then check if mouse is over tooltip (GUI.tooltip == “name_text_field”) and value of text field is still default (Players*.name == “name” ) then clear text field.*
If mouse is out of text field and text field is empty, then set text field value to default.

You can do this using tooltip:

public class Test : MonoBehaviour
{
    private string _default = "name";
    private string _player_name = "";
    private string _tooltip = "player_name_field";

    private void OnGUI()
    {
        GUI.BeginGroup(new Rect(0, 0, 200, 30), new GUIContent("", _tooltip));
        _player_name = GUI.TextField(new Rect(0, 0, 200, 30), _player_name);
        GUI.EndGroup();

        if (UnityEngine.Event.current.type == EventType.Repaint)
        {
            if (GUI.tooltip == _tooltip)
            {
                if (_player_name == _default) _player_name = "";
            }
            else
            {
                if (_player_name == "") _player_name = _default;
            }
        }
    }
}

The idea is when is mouse over textfield and it has default value then clear it. And when mouse is out and textfield is cleared, then set it to default value.