// Place this as an instance in a script to get access to any Text element in that script's object. // if null, no text mesh exists in hierarchy or failed to get/add DynamicText script. public static DynamicText GetTextMesh(JDMonoBehavior source) { var textObject = source.GetComponentInChildren<TextMesh>(); if (textObject != null) { DynamicText textual = textObject.GetComponent<DynamicText>(); if (textual == null) { textual = textObject.gameObject.AddComponent<DynamicText>(); } return textual; } return null; }
// gets a weapon bar if it exists on this object. public static WeaponBar GetWeaponBar(JDMonoBehavior source) { var bar = source.GetComponentInChildren<WeaponBar>(); return bar; }