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 /
This question was closed Aug 31, 2015 at 09:04 PM by Ashky for the following reason:

The question is answered, right answer was accepted

avatar image
2
Question by Ashky · Mar 02, 2015 at 07:58 PM · c#uicanvaschildunity 4.6

How to get a certain child from a Canvas?

Hello Unity Community!

I am trying to dynamically modify a Text from the UI. My hierarchy is as follows: Canvas->Panel->CurrencyText.

I am trying to modify the content of CurrencyText with:

         _currencyText = GameObject.Find("Canvas").GetComponentInChildren<Text>();
         _currencyText.text = string.Format("{0:0,0.00}", _currency);

However, these lines will only get the first Text type child from Panel. I will need to modify multiple Text type children.

So, how can I possibly access a certain child instead of just the first in the hierarchy?

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

1 Reply

  • Sort: 
avatar image
6
Best Answer

Answer by Aevitas · Mar 03, 2015 at 10:37 PM

  1. You could link it by adding a variable, either public, or [Serializable] private/protected

  2. You could find all components with GetComponentsInChildren(), this will return an array of all Text components in all children AND itself (although the function name would state otherwise). You could then iterate on this array to find the correct one, either by name, tag, values, other components...

  3. You could look it up by its hierarchy path name: gameObject.Find("Name/Childname/Childname").GetComponent();

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 Ashky · Mar 04, 2015 at 12:56 PM 0
Share

Thank you very much. I'm at work right now and I can't try out any of the solutions. However, this seems to clear up all my problems. Thanks!

Follow this Question

Answers Answers and Comments

21 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

Related Questions

How do you Instantiate Text as Child of Canvas c# 1 Answer

Canvas Button OnClick() function arguments 1 Answer

Multiple Cars not working 1 Answer

Why can't I reference Graphics Raycaster in my gameObject? 1 Answer

Distribute terrain in zones 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