Preparing a canvas in 3D mode.

        void OnEnable()
        {
            m_TargetCameraState.SetFromTransform(transform);
            m_InterpolatingCameraState.SetFromTransform(transform);

            m_TargetCameraState.x = 1;
            m_TargetCameraState.y = 1;
            m_TargetCameraState.z = 1;

            GameObject mPlane = GameObject.Find("Background");


        }

I figured out how to move the camera’s position from the SimpleCameraController.

Now what I would like to do is programmatically create a canvas to draw to that is in sized to match the cameras rectangle in my 3DWithExtras project. I tried at first to put a panel but I couldn’t figure out how to use a panel to draw lines and arcs with.

I see that there is a camera rect and also a rectpixels to use but need some help in putting it all together.

Thank You!

Creating a canvas and ui structure in code is really hard. There’s just a metric buttload of fiddly diddly little things that the Unity editor just takes care of for you. You can do it, but be prepared for a hard slog, and you’ll be referring to the Canvas/UI source code (available online) throughout, and it will still be hard and cause a lot of head-scratching. Source: I have tried.

Much better is to make a prefab, instantiate it where you want, then adjust only the parameters you need for it.

Alternately, use another camera and just overlay the UI. That’s usually the easiest, unless you must have a world space UI.

1 Like

I finally figured out how to use a camera space overlay with a canvas and also a canvas could be a child of a panel. It’s tough rocks to crack for me right now.