onMouseDown and continous animation problem.

I want that when I click on the object it moves continuously.
I am doing scripting for the first time.So please explain me in detail and in simple way…I did this.I know this is stupid.

function onMouseDown ()
{
	Update();
}

function Update()
{
	transform.Translate(Vector3(0,0,1)*Time.deltaTime);
}

Better to do within the Update() method as

function Update() {
    if(Input.GetMouseButtonDown(0))
        Debug.Log("Pressed left click.");
    if(Input.GetMouseButtonDown(1))
        Debug.Log("Pressed right click.");
    if(Input.GetMouseButtonDown(2))
        Debug.Log("Pressed middle click.");

// do your transform action on whichever you need.
}

or

    // Detects clicks from the mouse and prints a message
    // depending on the click detected.
    function Update() {
        if(Input.GetMouseButton(0))
            Debug.Log("Pressed left click.");
        if(Input.GetMouseButton(1))
            Debug.Log("Pressed right click.");
        if(Input.GetMouseButton(2))
            Debug.Log("Pressed middle click.");
    }

OnMouseDown only works on desktop/web builds as well unless you add it to mobile to use as touches.

//  OnTouchDown.cs
//  Allows "OnMouseDown()" events to work on the iPhone.
//  Attach to the main camera.

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

	public class OnTouchUp : MonoBehaviour
	{
		void Start() {
		}

		void Update () {

			// Code for OnMouseDown in the iPhone. Unquote to test.
			RaycastHit hit = new RaycastHit();
			for (int i = 0; i < Input.touchCount; ++i) {
				if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {

				// Construct a ray from the current touch coordinates
				Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
				if (!Physics.Raycast(ray, out hit)) {
					if(hit.transform != null) {
						if(hit.transform.gameObject != null) {
							hit.transform.gameObject.SendMessage("OnMouseUp", SendMessageOptions.DontRequireReceiver);
						}
					}
			      }
			   }
		   }
		}
	}

and

//	OnTouchDown.cs
//	Allows "OnMouseDown()" events to work on the iPhone.
//	Attack to the main camera.


using UnityEngine;
using System.Collections;
using System.Collections.Generic;

	public class OnTouchDown : MonoBehaviour
	{
		void Start() {
		}

		void Update () {

			// Code for OnMouseDown in the iPhone. Unquote to test.
			RaycastHit hit = new RaycastHit();
			for (int i = 0; i < Input.touchCount; ++i) {
				if (Input.GetTouch(i).phase.Equals(TouchPhase.Began)) {

				// Construct a ray from the current touch coordinates
				Ray ray = Camera.main.ScreenPointToRay(Input.GetTouch(i).position);
				if (Physics.Raycast(ray, out hit)) {
					if(hit.transform != null) {
						if(hit.transform.gameObject != null) {
							hit.transform.gameObject.SendMessage("OnMouseDown", SendMessageOptions.DontRequireReceiver);
						}
					}
			      }
			   }
		   }
		}
	}
}

Here is a simple script. Clicking on the game object will toggle between moving and not moving.

private var moving = false;

    function OnMouseDown () {
        moving = !moving;  // Mouse click toggles
    }
     
    function Update()
    {
        if (moving)
            transform.Translate(Vector3(0,0,1)*Time.deltaTime);
    }