Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Created June 21, 2018 13:02
Show Gist options
  • Save onmyway133/b0c38384467330119af52a6eeda2635c to your computer and use it in GitHub Desktop.
Save onmyway133/b0c38384467330119af52a6eeda2635c to your computer and use it in GitHub Desktop.
public GameObject makeCanvas() {
GameObject canvasObject= new GameObject("Canvas");
Canvas canvas = canvasObject.AddComponent<Canvas>();
canvas.renderMode = RenderMode.WorldSpace;
CanvasScaler scaler = canvasObject.AddComponent<CanvasScaler>();
scaler.scaleFactor = 10.0f;
scaler.dynamicPixelsPerUnit = 10.0f;
GraphicRaycaster graphic = canvasObject.AddComponent<GraphicRaycaster>();
canvasObject.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, 3.0f);
canvasObject.GetComponent<RectTransform>().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 3.0f);
return canvasObject;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment