public static GameObject FindUIRoot() { #if UGUI GameObject root = new GameObject("Canvas"); Canvas can = root.AddComponent <Canvas>(); can.renderMode = RenderMode.ScreenSpaceOverlay; var scaler = root.AddComponent <CanvasScaler>(); scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.referenceResolution = new Vector2(1280, 720); scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Expand; root.AddComponent <GraphicRaycaster>(); return(root); #elif NGUI UIRoot root = GameObject.FindObjectOfType <UIRoot>(); if (root == null) { GameTools.CreateUI(false); } return(GameObject.FindObjectOfType <UICamera>().gameObject); #endif return(null); }