Skip to content

Instantly share code, notes, and snippets.

@akbiggs
Created December 9, 2015 18:47
Show Gist options
  • Save akbiggs/0b779ad9d075fec2ea44 to your computer and use it in GitHub Desktop.
Save akbiggs/0b779ad9d075fec2ea44 to your computer and use it in GitHub Desktop.
using UnityEngine;
using UnityEngine.UI;
public class ShowNumberOfCanvasChildren : MonoBehaviour
{
private GameObject _canvas;
private Text _childText;
private void Start()
{
// grab an object in the scene called Canvas
_canvas = GameObject.Find("Canvas");
// and grab some text in a child of the object
// that this script is attached to
_childText = this.transform.FindChild("ChildText").GetComponent<Text>();
}
private void Update()
{
// on every frame, modify that text
_childText.text = "Canvas child count: " + _canvas.transform.childCount;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment