Deactivate running of Update function

I have added 2 scripts to one object… (1) MoveBlock and (2) StopBlockMovement
In moveblock, the void Update function takes a boolean value from the void OnMouseDown function… based on the value of the boolean, if the mouse is clicked, the object moves(used transform.translate for movement)…

The second script(StopBlockMovement) is where i want to stop movement of the object… i want to just deactivate the Update function of the MoveBlock script, until the OnMouseDown condition is true again…

Code:

(MoveBlock):

    public class MoveBlockDown : MonoBehaviour {
        bool pressed=false;
        
        // Use this for initialization
        void Start(){}
        	
        // Update is called once per frame
        void Update()
        {
        if(pressed==true)
            transform.parent.Translate(Vector3.down*Time.deltaTime*4);
        }

      void OnMouseDown()
      {
      pressed = true;
//my condition
//need to re-activate the update here
      }
}

you could do something like

	void Update () 
	{
		if (Input.GetMouseButton (0)) 
		{
			transform.parent.Translate(Vector3.down*Time.deltaTime*4);
		}
	
	}

it should work, no need to use OnMouseDown

You can get a reference to the MoveBlock script in your StopBlockMovement script then you can set enabled flag to false for that script and it will stop the running of update function (along with any other functions) from MoveBlock script.

But there is also an another method discussed in this question: Turn off function

Hope this helps!