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
}
}