Created
April 13, 2017 14:28
-
-
Save rsodre/5fceabbbba4beeebdebdccf1a47b9768 to your computer and use it in GitHub Desktop.
Unity tip: Work with your canvas in Camera space, switch to Overlay on Play.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
// Unity tip" | |
// Usually it is desired that the HUD canvas is separated from Camera effects, or "ScreenSpaceOverlay" mode | |
// But Overlay canvases are terrible to work with | |
// So keep your canvas in "Screen Space Camera", and switch it automatically to Overlay when the game starts | |
public class CanvasRenderModeSwitcher : MonoBehaviour | |
{ | |
public RenderMode newRenderMode = RenderMode.ScreenSpaceOverlay; | |
void Start () | |
{ | |
Canvas canvas = GetComponent<Canvas>(); | |
if (canvas != null) | |
canvas.renderMode = newRenderMode; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment