I want to build a short simple scene in which there’ll be a slider bar (can be a 3D mesh of a semi-circular shape that is being looked by the camera from the middle of Top and Front position).
The user has to be able to use the mouse to drag a handle on the bar and change the values that’ll effect another element. That bar is actually just meant to rotate the 3D model when the user drags the handle form the beginning tip the end. I’m aware of handling the rotation and can achieve the effect using the inbuilt GUI element in Unity but I’m looking to build a better looking bar (and as mentioned above of a different shape than the default) and was looking for steps on how to proceed with the same. I’ve looked up Asset Store and there aren’t any readily available such elements that I could find and other tutorials links point to using the inbuilt GUI slider bar.
For a custom slide bar, you can use GUITextures : you create a GUITexture, make it as your bar, you create a second one, make it as the slide button. Then you just have to use OnMouseDrag in the script attached to the slide button. In the OnMouseDrag function you just have to adjust the pixel inset, with value you get from Input.mousePosition.y or .x, depending if your slide bar is vertical or horizontal.
I’m going to amend that a bit. GUITextures are a very old, almost legacy class at this point. Using Sprites for this sort of thing is a better habit to get into.
Thanks for the response. Will I be able to get a semi-circular/circular slider bar using the above technique? For e.g.: Consider the bar of the following shape (being seen by the camera from middle of top and front camera position)
I checked out some other threads and was of the view that such GUI elements will only be stuck to the screen and won’t have this kind of flexibility as with 3D elements.
Same question as above to SmokyZebra. Will GUITextures/Sprites allow this kind of flexibility? What I’d like to do is move a slider handle over a bar and if the Sprites/Textures won’t be able to give the above sort of appearance, it’d interesting to know of some links where a similar implementation of a 3D slider bar can be done.
It’s not a LOT harder. You’d mostly have to adjust the way it calculates the position - add in some Mathf.Sin to figure the Y position and some Mathf.Cos for the X position.
Well, if your math skills are not great, I suppose that would be a lot harder…
Or, you can add a member variable of type AnimationCurve, which has your desired curve of the slider , then evaluate the actual slider objects position based on that curve.