Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
-1
Question by missD · Feb 01, 2014 at 03:35 PM · buttontextfield

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 :)

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);
         }
     }
 }
Comment
Add comment · Show 4
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image robertbu · Feb 01, 2014 at 05:01 PM 0
Share

Posting your current code will get you a more accurate answer. See GUI.Label().

avatar image missD · Feb 02, 2014 at 10:47 AM 0
Share

sorry,it's my first time asking here so,how to post the code?

avatar image robertbu · Feb 02, 2014 at 04:13 PM 0
Share

You can click on the 'edit' link in the bottom left corner of your question to edit your question. Copy your code from $$anonymous$$onodevelop and paste it into the edit view. Select your code and use the '101/010' button to format your code.

avatar image missD · Feb 03, 2014 at 11:46 AM 0
Share

alright,that's my current code. thank you, so now do you know what i should use ins$$anonymous$$d of using form code?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Ibzy · Feb 03, 2014 at 12:21 PM

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));
     }
     }
 }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image missD · Feb 03, 2014 at 12:45 PM 0
Share

Thanks for the help! Yeah that's what I mean,so user can play with name "Player" or they can change it to whatever they want. But the text "Player" still cannot be deleted,got any idea why?

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

19 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Press Return in TextFiled to press button 0 Answers

Textfield button PLZ HELP!!! 1 Answer

Type in TextField to make buttons press and vice versa 0 Answers

GUI.Textfield backspace control + Button Style problem 0 Answers

when button pressed, textfield appears 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges