using UnityEngine; using System.Collections; using System.Reflection; public class UIText { private MonoBehaviour _source; private PropertyInfo textProp; public UIText(MonoBehaviour src) { _source = src; textProp = src.GetType().GetProperty("text"); } public string text { get { return (string)textProp.GetValue(_source, null); } set { textProp.SetValue(_source, value, null); } } } public class HudController : UiController { public MonoBehaviour notifyText; public MonoBehaviour actionText; private UIText _notifyText; public UIText NotifyText { get { if (_notifyText == null) { _notifyText = new UIText(notifyText); } return _notifyText; } } private UIText _actionText; public UIText ActionText { get { if (_actionText == null) { _actionText = new UIText(actionText); } return _actionText; } } public void SetNotify(string notify) { NotifyText.text = notify; } public void SetAction(string action) { ActionText.text = action; } // Use this for initialization void Start() { var txt = transform.GetChild(0); var c = txt.GetComponents(); Debug.Log("Components count: " + c.Length); Debug.Log("Component type: " + c[0].GetType().Name); } // Update is called once per frame void Update() { } }