Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Awake()
- {
- if(instance != null)
- {
- DestroyImmediate(gameObject);
- return;
- }
- instance = this;
- // Create the canvas and set it to screen space overlay mode
- // ---------------------------------------------------------
- var canvas = new GameObject("Canvas", typeof(Canvas)).GetComponent<Canvas>();
- canvas.transform.SetParent(transform, false);
- canvas.renderMode = RenderMode.ScreenSpaceOverlay;
- canvas.sortingOrder = sortOrder;
- // Add a CanvasGroup component so we can make it non-blocking and control the alpha
- // --------------------------------------------------------------------------------
- group = canvas.gameObject.AddComponent<CanvasGroup>();
- group.alpha = 0f;
- group.interactable = false;
- group.blocksRaycasts = false;
- group.gameObject.SetActive(false);
- // Add an image, set it's colour and scale it to ensure there is no border
- // -----------------------------------------------------------------------
- var image = new GameObject("image", typeof(Image)).GetComponent<Image>();
- image.transform.SetParent(canvas.transform, false);
- image.color = fadeColour;
- image.transform.localScale = new Vector2(1.25f, 1.25f);
- // Set the image to be centred and fill the screen,
- // and set anchors to stretch the image if screen size changes
- // -------------------------------------------------------------
- var imageRect = image.GetComponent<RectTransform>();
- imageRect.anchorMin = Vector2.zero;
- imageRect.anchorMax = Vector2.one;
- imageRect.anchoredPosition = Vector2.zero;
- imageRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,Screen.width);
- imageRect.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,Screen.height);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement