private GameObject CreateCreationUnitButton(Vector2 center, UnitTypes type, int position) { GameObject canvasObject = new GameObject("UnitCreationButtonCanvas"); Canvas canvas = canvasObject.AddComponent <Canvas>(); canvas.tag = "UnitCreationButton"; canvasObject.AddComponent <GraphicRaycaster>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; GameObject buttonObject = new GameObject("CreationUnitImage"); Image image = buttonObject.AddComponent <Image>(); image.transform.parent = canvas.transform; image.rectTransform.sizeDelta = creationQueueButtonSize * 0.9f; image.rectTransform.position = center; Sprite buttonImage = GetImageForType(type); if (buttonImage != null) { image.sprite = buttonImage; } else { image.color = new Color(1f, 1f, 1f, 1f); } Button button = buttonObject.AddComponent <Button>(); button.targetGraphic = image; button.onClick.AddListener(() => { if (position == 0) { if (currentResource != null) { currentResource.cancelUnitQueue(); } else if (currentBarrack != null) { currentBarrack.cancelUnitQueue(); } ShowCreationQueue(); } }); GameObject shadowObject = new GameObject("UnitCreationShadow"); Image shadow = shadowObject.AddComponent <Image>(); shadow.transform.parent = canvas.transform; shadow.rectTransform.sizeDelta = creationQueueButtonSize * 0.9f; shadow.rectTransform.position = center; shadow.type = Image.Type.Filled; shadow.fillMethod = Image.FillMethod.Radial360; shadow.transform.Rotate(180, 0, 0); Texture2D shadowTexture = (Texture2D)Resources.Load("creationUnitShadow"); if (shadowTexture) { shadow.sprite = Sprite.Create(shadowTexture, new Rect(0, 0, shadowTexture.width, shadowTexture.height), new Vector2(0.5f, 0.5f)); } return(canvasObject); }