Slider without GUILayout

Hi Everybody,

I have a small question.
Does anybody know if it is possible (with javascript) to make a horizontal or vertical slider without GUILayout?
I want to make a slider from a gameobject (the same way as the buttons I have made from gameobjects with GetMouseButtonDown(0)).

To answer your question directly (more for anyone coming across this thread later from search engines), yes – Unity - Scripting API: GUI.HorizontalSlider is a link to the documentation to the non-layouted version of the slider.

That isn’t the same thing as what you are describing though – you are describing a slider without GUI at all. Assuming you want this to work anywhere, on a camera in any orientation, and still be visually horizontal/vertical, you just need to lock the object’s position on two camera-aligned planes (eg. camera Z and camera Y for a horizontal slider) to constrain motion of an object to a single axis (camera x), and then set min/max values along that axis obtained, by for example, by getting the screen point on a ray Z deep. Probably multiply the camera’s rotation in to the position to rotate it around the camera so that it always nicely faces things and you don’t change the value when the camera rotates. It wouldn’t be hard, but it would be hassle enough to need a pretty compelling case to not use GUI, I think. If your camera is fixed, or if you don’t need motion relative to the camera, it becomes even easier. Unfortunately, writing it in javascript sounds not very fun.

Thanks for your quick reply.

Yes, I mean a slider without GUI at all.
I understand that it’s not very easy but I will give it a try.
Thanks.

I guess you could make a game object that only moves in X when there is a mouse drag.
than you could make it that it cannot go further than a certain distance.