Horje
unity set parent canvas Code Example
unity set parent canvas
[MenuItem("GameObject/UI/Switch")]
static void Switch()
{
    //Create new GameObject
    GameObject go = new GameObject("switch");


    //Find Canvas in the Scene
    Canvas canvas = (Canvas)GameObject.FindObjectOfType(typeof(Canvas));

    //Get Canvas GameObject
    GameObject canvasGameObject = canvas.gameObject;

    //Make the new GameObject child of the Canvas
    go.transform.parent = canvasGameObject.transform;
    go.transform.localPosition = Vector3.zero;

    //Change the new GameObject Layer to UI
    go.layer = 5; //Or go.layer = canvasGameObject.layer;

    //Add Rect Transform to it
    go.AddComponent<RectTransform>();
}




Csharp

Related
load information with txt file to uwp c# Code Example load information with txt file to uwp c# Code Example
deserialize object to dictionary c# Code Example deserialize object to dictionary c# Code Example
how to resize a panel unity Code Example how to resize a panel unity Code Example
turtle graphics face in direction Code Example turtle graphics face in direction Code Example
new material unity Code Example new material unity Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
11