How can i use a bool to decide when to move the character or not ?

I got mixed it all and got confused.
What i want to do is when i click the right mouse button don’t call the GetInteraction(); function when i click on the left mouse button call it.
Like a switch/pause button. Click on right will stop calling it click on left will keep calling it. I tried to use the toMove bool variable but messed it all.

private void Update()
    {
        //if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
        if (Input.GetMouseButtonDown(1) && toMove == true)
        {
            toMove = false;
        }
        else
        {
            if (Input.GetMouseButtonDown(0) && toMove == false && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
            {
                toMove = true;
                GetInteraction();
            }
        }
    }

@Chocolade

something like this?

 void Update() {
 if (Input.GetMouseButtonDown(0) && to Move == false && 
 !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject) 
      {
      toMove = true;

      }
 if (Input.GetMouseButtonDown(1) && toMove == true) 
      {

      toMove = false;
      }
 if (toMove == true) 
      {
      GetInteraction();
      }
 }

I’m not actually sure what GetInteraction() does or is supposed to do, but hopefully it’s something like this that you are looking for? If this doesn’t work could you provide if GetInteraction(); is something you are trying to call every frame whentoMove = true or something you only want to call when it’s true and you are right-clicking.

Anyways, hope this works

I’m not sure how exatly you want this to work. Should GetInteraction() only be called while the left button is pressed? Or do you want GetInteraction() to be continuously called after a left click until you click right?

This will call GetInteraction() as long you hold left and the cursor is not over an object:

void Update()
{
  if (Input.GetMouseButtonDown(0) && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
  {
     GetInteraction();
  }
}

This will initiate a constant calling of GetInteraction() with a left click until you right click to cancel:

private bool moving = false;

void Update()
{
  if (Input.GetMouseButtonDown(0))
  {
    moving = true;
  }
  if (Input.GetMouseButtonDown(1))
  {
     moving = false;
  }

  if (moving && !UnityEngine.EventSystems.EventSystem.current.IsPointerOverGameObject())
  {
     GetInteraction();
  }
}

I could think of some more cases but maybe those 2 are already helpful?