click the button and text field appears below the button

Hey i’m making a game for my thesis now, and i need help,
I’m using c# AND i have these select your character scene with button with image of character in it. But I want it to be when user clicked the button,the text field with default name will appear below the button instead of text field in the button.

please anybody help me? thank you :slight_smile:

these are my current code:

using UnityEngine;
using System.Collections;

public class SelectingCharacter : MonoBehaviour {

	public Texture2D texture = null;
	
	public float guiPlacementY1;
	public float guiPlacementY2;
	public float guiPlacementY3;
	public float guiPlacementY4;
	
	public float guiPlacementX1;
	public float guiPlacementX2;
	public float guiPlacementX3;
	public float guiPlacementX4;
	
	private bool showForm = false;
	private string myText = "";
	
void OnGUI(){	
		if (!showForm)
		{
			if (GUI.Button (new Rect(0,0,100,20), "Show Form"))
				showForm = true;
		}
		else
		{
			myText = GUI.TextField(new Rect(0,0,100,20), "Player");
		}
		
		GUI.Box (new Rect(350,80,600,450), "");
		if (GUI.Button(new Rect(Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .1f, Screen.height * .2f), "Male"))
			{
				if (!showForm)
					showForm = false;
				else
					showForm = true;
}
		else if (GUI.Button(new Rect(Screen.width *guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .1f, Screen.height * .2f), "Female"))
			{
				if (!showForm)
					showForm = false;
				else
					showForm = true;
}
		else if (GUI.Button(new Rect(Screen.width *guiPlacementX3, Screen.height * guiPlacementY3, Screen.width * .1f, Screen.height * .1f), "Back"))
			{
				Application.LoadLevel(0);
}
			
		else if (GUI.Button(new Rect(Screen.width *guiPlacementX4, Screen.height * guiPlacementY4, Screen.width * .1f, Screen.height * .1f), "Next"))
			{
				Application.LoadLevel(5);
		}
	}
}

Hi MissD,

Firstly, I think you can replace
if (!showForm)
showForm = false;
else
showForm = true;
With showForm = !showForm as you are using that if statement as a toggle - this will tidy the code up a little.

If I understand your question correctly, you would like it to say “Player” in a textfield that you can then choose to change?

I hit this snag myself and the result I got was something like:

using UnityEngine;
using System.Collections;
 
public class SelectingCharacter : MonoBehaviour {
 
    public Texture2D texture = null;
 
    public float guiPlacementY1;
    public float guiPlacementY2;
    public float guiPlacementY3;
    public float guiPlacementY4;
 
    public float guiPlacementX1;
    public float guiPlacementX2;
    public float guiPlacementX3;
    public float guiPlacementX4;
 
    private string myText = "Player";
    private bool showName = false;
 
void OnGUI(){   

       GUI.Box (new Rect(350,80,600,450), "");
       if (GUI.Button(new Rect(Screen.width * guiPlacementX1, Screen.height * guiPlacementY1, Screen.width * .1f, Screen.height * .2f), "Male"))
	{
	  showName = true;
	}
       if (GUI.Button(new Rect(Screen.width *guiPlacementX2, Screen.height * guiPlacementY2, Screen.width * .1f, Screen.height * .2f), "Female"))
	{
	  showName = true;
	}
       if (GUI.Button(new Rect(Screen.width *guiPlacementX3, Screen.height * guiPlacementY3, Screen.width * .1f, Screen.height * .1f), "Back"))
	{
          Application.LoadLevel(0);
	}
 
       if (GUI.Button(new Rect(Screen.width *guiPlacementX4, Screen.height * guiPlacementY4, Screen.width * .1f, Screen.height * .1f), "Next"))
	{
          Application.LoadLevel(5);
	}

       if (showName)
	{
	  GUI.TextField(new Rect(0,0,100,20), myText));
	}
    }
}