Skip to content

Instantly share code, notes, and snippets.

@rsodre
Created April 13, 2017 14:28
Show Gist options
  • Save rsodre/5fceabbbba4beeebdebdccf1a47b9768 to your computer and use it in GitHub Desktop.
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.
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