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 /
  • Help Room /
avatar image
0
Question by Mahunreah · Feb 05, 2021 at 09:27 PM · tagfindgameobjectswithtaggetcomponentsinchildren

How to find certain TextMeshProUGUI if multiple are attached?

I have an inventory with six slots. Each slot has three TextMeshProUGUI attached: singleGoldAmount, stackSize, resultingGoldAmount. These TextMeshProUGUI are tagged with names corresponding to their purpose.

I want the inventory in Start() to find each TextMeshProUGUI-Element and put them in a list like private TextMeshProUGUI [] singleGoldAmountText, vice versa for stacksize and resultingGoldAmount. I've tried FindWithTag, but didn't get the solution I was looking for.

I've tried to solve this for two days but I feel like I'm not making any progress. By now, I'm probably blind to the obvious solution and too stupid to abstract from this particular problem.

This is as far as I came: using System.Collections.Generic; using System.Collections; using UnityEngine; using System; using TMPro; using UnityEngine.Serialization;

 public class Inventory : ItemContainer
 {
     [SerializeField] List<Item> startingItems;
     [SerializeField] Transform itemsParent;
 
     // Blubb testing stuff here
     [SerializeField] List<Werkstatt_Slot> werkstattSlot;
     [SerializeField] Transform werkstattSlotTrans;
     // Blubb ending testing
 
 
 
     public string Goldwert;
 
     
     public void Start() 
     {
         SetStartingItems();
         Init();
     }
 
     private void Init()
     {
         for (int i = 0; i < werkstattSlot.Count; i++)
         {
             // ?? I'm fairly sure I need this to fill the list?
         }
     }
 
     private void OnValidate () 
     {
         // GoldWertFeld = TextMeshProUGUI.FindGameObjectsWithTag("Goldwert"); // NOPE NOT WORKING
         if (itemsParent != null)
         {
             itemSlots = itemsParent.GetComponentsInChildren<ItemSlot>(); //Works like a charm
             werkstattSlot = werkstattSlot.GetComponentsInChildren<Werkstatt_Slot>(); //Does not work
             // itemWert = itemsParent.GetComponentsInChildren<TextMeshProUGUI>(); //Works, but only as long as there is only ONE type of TextMeshProUGUI... I have three now.
             // itemWert = werkstattSlotGO.FindWithTag("Goldwert").GetComponentsInChildren<TextMeshProUGUI>(); //This was another try. Didn't work.
             //    itemWert = GameObject.FindWithTag("Goldwert").GetComponentsInChildren<TextMeshProUGUI>(); // This one finds a single entry. 
 
             // itemWert = GoldWertFeld.GetComponent<TextMeshProUGUI>(); // Nope
         }
 
         SetStartingItems();
         Init();
     }
 
 
     private void SetStartingItems()
     {
         int i = 0;
         for (; i < startingItems.Count && i<itemSlots.Length; i++)
         {
             itemSlots[i].Item = startingItems[i].GetCopy();
         }
 
         for (; i<itemSlots.Length; i++)
         {
             itemSlots[i].Item = null;
         }
     }    
 }

Could somebody help me out? Pointing me to a tutorial would be fine, too, I am just really stuck in a circle here.

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

0 Replies

· Add your reply
  • Sort: 

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

153 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

Related Questions

Navmesh, help setting position to nearest tag? (Javacript) 0 Answers

How to use 2 tags in FindGameObjectsWithTag. 2 Answers

Turn on/off renderer for objects found with "FindGameObjectsWithTag" 1 Answer

How do I use arrays, with getcomponent? 2 Answers

Check if there's no GameObject with specific tag in the field (in the camera view) 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