Scrollbar to move left and right

Okay so I am trying to make it so that you can move the character left and right with the new UI scrollbar. I am using this script.

public float moveSpeed;

private float moveVelocity;

public GameObject scrollbar;

void Update () {
	
		moveVelocity = 0f;

		if (scrollbar >= 0.5) 
		{
			moveVelocity =  moveSpeed;
		}
		
		if(scrollbar <= 0.5)
		{
			moveVelocity = -moveSpeed;
		}  
}

So the problem is that I keep getting this error,

Assets/Move.cs(27,21): error CS0019: Operator >' cannot be applied to operands of type UnityEngine.GameObject’ and `double’

Assuming that your public scrollbar object indeed has an UI.Scrollbar component attached, you should try this

public GameObject scrollbar;
//Add a reference to the scrollbar component
Scrollbar myScrollbar;

void Start() {
  myScrollbar = scrollbar.GetComponent<Scrollbar>();
}
 
 void Update () {
     
         moveVelocity = 0f;
 
         if (myScrollbar.value >= 0.5) 
         {
             moveVelocity =  moveSpeed;
         }
         
         if(scrollbar.value <= 0.5)
         {
             moveVelocity = -moveSpeed;
         }  
 }

Don’t forget to add the reference to the UnityEngine.UI namespace at the beginning of your class so you can have access to the objects. Just go to the top of your class and add:

using UnityEngine.UI;

Regards