- Home /
Organised UI List of multiple different Gameobjects by tag
Hi Everyone
I currently have a UI system using text mesh pro that tracks the amount of multiple different gameobjects by tag in a scene. However the tracked objects are always displayed in the UI list even if there's none & they don't sort by amount. Which is an issue when having lots of objects.
I would like to create a system that tracks all of the game objects, but only shows them on the list if there's at least 1 & then have them sorted by highest amount.
Here is an image of what I am trying to achieve.
Here is my current code, I know it isn't great but creating UI lists isn't my strong suit. Thank you for any answers in advance.
public class SceneObjectCounter : MonoBehaviour
{
public TMP_Text Object1Text;
public TMP_Text Object2Text;
public TMP_Text Object3Text;
public int Object1Count;
public int Object2Count;
public int Object3Count;
private GameObject[] getObject1Count;
private GameObject[] getObject2Count;
private GameObject[] getObject3Count;
void Start()
{
StartCoroutine(ObjectCounter());
}
void Update()
{
if (!EventSystem.current.IsPointerOverGameObject())
if (Input.GetMouseButtonUp(0)||Input.GetMouseButtonUp(1))
{
StartCoroutine(ObjectCounter());
}
}
IEnumerator ObjectCounter ()
{
yield return new WaitForSeconds(0);
getObject1Count = GameObject.FindGameObjectsWithTag("OBJ1");
getObject2Count = GameObject.FindGameObjectsWithTag("OBJ2");
getObject3Count = GameObject.FindGameObjectsWithTag("OBJ3");
Object1Count = getObject1Count.Length;
Object2Count = getObject2Count.Length;
Object3Count = getObject3Count.Length;
Object1Text; = Object1Count.ToString() + " X Object 1";
Object2Text; = Object2Count.ToString() + " X Object 2";
Object3Text; = Object3Count.ToString() + " X Object 3";
yield return null;
}
}
So you want to count objects in the scene with specific tags everytime when you release L$$anonymous$$B or R$$anonymous$$B and the display sorted result in UI?
Your answer
![](https://koobas.hobune.stream/wayback/20220612213555im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Simple Tree View UI in a game? 0 Answers
A node in a childnode? 1 Answer
images assigned to gameobjects by tag 2 Answers