// Get Canvas public static Canvas GetCanvas(GameObject gameObject = null) { Canvas canvas = (gameObject != null) ? UGUITools.FindInParents <Canvas>(gameObject) : null; if (canvas == null) { canvas = GameObject.FindObjectOfType <Canvas>(); } // If no root found, create one if (canvas == null) { canvas = AddCanvas(gameObject); } return(canvas); }