Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
0
Question by dovahkiinSe · Aug 19, 2019 at 11:48 AM · uibuttontext mesh

Get a text value using button click

Hello, I'm developing an UI system for my project. The UI will contain a list of UI 'Panels' where inside the panels there will be some texts and a button. I've created the list of the panels by Instantiation 'Panel Gameobject' . My problem is inside the panels I want to get the "Game ID" text value individually by clicking the button inside each panel. I'm nearly not getting any solution regarding this problem.

It would be very helpful if anyone get me out from this nightmare . Here is a picture I'vealt text attached:

problem.png (43.9 kB)
Comment
Add comment · Show 3
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 I_Am_Err00r · Aug 20, 2019 at 02:59 PM 0
Share

Before I provide a solution, I want to make sure I understand your problem.


You want the GameID to change to whatever value that you have coded into the button? So, if when I hit button, and I want GameID to say "Level 1" it will say "Level 1" in that GameID?

avatar image dovahkiinSe I_Am_Err00r · Aug 28, 2019 at 06:59 AM 0
Share

Actually I tried to get the exact GameID text "ABC123" while I click the button next to it. I've taken these GameIDs from a list that I fetched from firebase database. Thanks for the help :) . I tried to solve this problem internally from the script but failed, later on I used drag n drop method which worked !

avatar image astechnolabs · Aug 01, 2021 at 09:46 AM 0
Share

Same problem here, I have thousands of row of Game ID, nd Thousands of Play button. so how Can I bind each and everyone, also, these thousands are dynamic so it's changing time by time. So need something like pass GAME_ID as parameter.

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Divinitize1 · Aug 20, 2019 at 04:17 PM

I'm not the best at using the most efficient coding practices, so others may point out if anything is wrong, but for the most part this is how i do it.

(you will need to drag the text object and button into the script in the inspector.)

 using UnityEngine.UI;
 
 public Text id1;
 public GameObject button1;
 public String textValue;
 
 //Can then either set the value of the text in script or the inspector.
 //Use this if you want to set it inside the script Inside a function like //Update()
 id1.text = "Whatever";
 
 
 //Button Press
 public void GetTextValue()
 {
 //Depends on what you want to do here with the actual value.
 //For this example i will put the value into a string.
     textValue = id1.ToString();
 }

Hope this is slightly helpful.

Comment
Add comment · Show 3 · 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 dovahkiinSe · Aug 24, 2019 at 07:08 AM 0
Share

Thanks for the solution. I actually tried to find the gameobject by script but unfortunately I was getting the value of last index of my Game_id list after clicking the panel buttons. Later on I tried similar method you provided and its working . Thank you very much for the help :) .

avatar image Amphelion · Aug 18, 2020 at 12:43 PM 0
Share

How can we get values from a gameobject array? What if I have like 100 different buttons with different values how can I get each own button value ?

avatar image astechnolabs Amphelion · Aug 01, 2021 at 09:48 AM 0
Share

I totally agreed. I have same problem, and have 1000s of rows from database, onclick go to 2nd page but with **GameID**

avatar image
0

Answer by Llama_w_2Ls · Aug 18, 2020 at 04:47 PM

@Amphelion for example, if we assume that we have a panel with 100 text UI elements in it, we could put all the text elements in an array by getting all the text components within the panel gameobject. Then we could get their values by writing:

     public GameObject ParentOfAllTexts;
 
     private void Start()
     {
         GetAndReturnValuesInAnArray();
     }
 
     void GetAndReturnValuesInAnArray()
     {
         Text[] texts = ParentOfAllTexts.GetComponentsInChildren<Text>();
 
         foreach (Text text in texts)
         {
             Debug.Log(text.text);
         }
     }

You could replace this with a button and get a certain component or value within those buttons quite simply as well.

Comment
Add comment · 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

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

199 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 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 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Make a button selectable for controller but not interactable 0 Answers

Unity UI Button states 1 Answer

Buttons become invisible when changing color (on Button or on Image) in script -1 Answers

Unity 5.0.2f1 UI Button OnClick Function 6 Answers

Using listeners to complete code errors 0 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