GUI Horizontal Slider


I was wondering if there's a way to convert a Horizontal Slider into something like an indicator that starts in the middle (the slider), and can move to both sides ?

Like for example you need to collect oxygen, otherwise you'll die. And that the right side represents 'full oxygen level' and the left side 'death'. The slider automatically goes to the left (depending on time) and whenever you collect oxygen the slider moves to the right. It would also be useful if it where to be an inactive element, so that the player can't click it.

Or is there a better way to try to achieve this kind of slider ?

Thanks in advance !

You could certainly do this with a HorizontalSlider. You have to pass in a value to the slider on each call to the GUI.HorizontalSlider function. You could keep updating this value with the oxygen level each frame and simply ignore the return value from the function.

As regards the timer, this is just a matter of storing the starting time value (obtained with Time.time and then on each frame, subtract the starting time from the current time. This gives you the elapsed time since the start. You could vary the position of the oxygen meter according to the amount of time that has passed.

Yes, certainly doable:

  void OnGUI() {
        val = GUI.HorizontalSlider(new Rect(250, 250, 1000, 3000), val, 0.5F, 720.0F);
	void Update(){
		if (val <= 720){
		val +=1;
		else val = 0;

Hope this helps