using prefabs to dyanmically create UI objects

Hi,

Im really confused about the new UI. In the old UI I could simply create a GUI element for a slider like so:

hSlideValue= GUI.HorizontalSlider(new Rect(25,25,100,30),hSlideValue,0.0f,1.0f);

Now I read in the docs for the new UI - Redirecting to latest version of com.unity.ugui

It’s possible now to create “Prefabs” for your UI elements and then reference them in code.

However, there is no documentation on how to reference these prefabs in code. For instance, how could I set the values as shown in the old gui (like Rect etc), in a prefab?

Cheers

There’s a great series of tutorials for the new UI here: Learn game development w/ Unity | Courses & tutorials in game design, VR, AR, & Real-time 3D | Unity Learn

Check 'em out. They’ll get you sorted.

My tutorial series is also pretty decent, once you’ve covered the basics on the learn section.

Here is one of the videos on dynamic UI that you may find relevant.

http://youtube.com/watch?v=0_QQtCyQ8aI

1 Like

The new UI works like everything else now. Prefabs work the same as any prefab. Access its components, just like a regular instantiated prefab. Only real differences are; some things need to be in place first like a Canvas and an EventSystem if you want input, and the instantiated prefabs need to be added to the Canvas or a child of a Canvas.

1 Like