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 Candide69 · Jul 19, 2017 at 12:26 AM · guitextonclickundo

How to deal with 100 UI text elements displayed as a grid and sharing same event logic

Hi, I'm a beginner in Unity and C#. I've spent hours and hours watching tutorials but I'm not sure what would be the best way to address following issue :

  • I will have on one single screen 100 UI "elements" displayed in ten lines of 10 columns. These elements will show no value in the begin. In my idea, each element could have two "properties" like LineName and ColumnNo.

  • when the user clicks on one of the elements, the system will calculate something based on the LineName and ColumnNo of this element (and other calculation parameters that I don't need to describe here) and display the result in the element.

  • I would like to be able to "undo" the player's choice. This means I need to know the last element that has been clicked after process. It would also be great if it was possible to set a backcolor to the selected element. After that, the player will click on a button to validate his choice, this would set the backcolor to default. The "Undo" option could be a button that retrieves the last clicked element and that sets the value back to null and the color to default.

  • I don't want to use a grid because of display purposes.

My questions :

Q1 : what kind of UI element would best suit to this expected behaviour ? - Text ? I saw a video where the person added a component to the UI Text in order to change its display properties (change color on MouseMove, change value onMouseClick...) - Input Text (the user won't input anything) ? - Buttons ? The Onclick event is available, the highlighted color is a standard behaviour, I know I can change the text shown by the button, etc... but it's strange for me to use buttons for that purpose. - another UI element ?

Q2 : do I have to call the function that calculates the result on each of the 100 elements or is there a way to avoid this ? I dream of an "OnClick" event shared by all the 100 elements that would do the job based on the element's "address" (LineName and ColumnNo).

Q3 : has someone seen something that looks like this in a sample project or a tutorial I could have a look at ?

I hope that at least one person has understood what I'm trying to do...

Thanks for any answer.

Comment
Add comment · Show 2
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 VioKyma · Jul 19, 2017 at 02:23 AM 0
Share

Is the calculated result a globally calculated thing (eg dependent on other items), or is it solely based on the item clicked?

avatar image Candide69 VioKyma · Jul 19, 2017 at 07:08 AM 0
Share

Thank you for your answer.

The result is a globally calculated thing depending on the lineName and on other items. To be sure that you understand what I'm trying to achieve, we can think of the Triple Yahtzee game. 5 dices have been thrown : 1 1 2 3 6. Clicking on an element of the "Ones" (3 fields on this line) will store the value 2 in the element clicked (two ones). Clicking on the first element of the third line (the Threes) would store 3 and so on.

==>I need two know on which element the player has clicked before calculating. For example the element with LineName = Threes and ColumnNo = 3. The calculation must now look for the threes, sum them up and save+show the result back in the element that had been clicked.

For the moment, I don't want to call the calculation function from each of the 100 elements, I guess there is a lighter solution. I'm probabling missing something somewhere but this is the first project I'm working on and I don't want to give up too soon ! ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by NorthStar79 · Jul 19, 2017 at 06:22 AM

q1 : take a look at grid layout group and layout element. q2 : yes you can create a logic like that, you may want to take a look at obj. oriented programming tips. q3: sorry but no,

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

Answer by Candide69 · Jul 22, 2017 at 05:21 AM

I found a workaround. I didn't want to change the code on 100 buttons (calling the same function with the ButtonName as parameter). What I did is that each of the buttons now calls the same function without any parameter but this function finds in the EventSystem what was the last button that was clicked (string selectedButtonName = EventSystem.current.currentSelectedGameObject.name;)

I don't know if that is the best solution but it works.

I didn't find a solution in the OOP tips (I was looking for an option to bind the 100 buttons to an "Object Class" that would have hold the event-logic (OnClick event would then be set on the class and not on each of the buttons).

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 NorthStar79 · Jul 22, 2017 at 05:33 AM 0
Share
 each of the buttons now calls the same function without any parameter but this function finds in the EventSystem what was the last button that was clicked

wow, that's a good workaround.

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

113 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

Related Questions

Detect Text in GUI; Print 1 Answer

GUI text font change 3 Answers

Limit on GUI Components? 0 Answers

Unity GUI text displaying as noise 1 Answer

GUI.PasswordField "•" makes "?" 1 Answer


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