Problem when moving a gameObject by a path, while the speed is increased.

I’ve made a script (2D) that when you hold the mouse on top of an object, it starts to store the coordinates creating a path. The script stop storing when the mouse is released (simulating drag event). I wanted this object to move through the path, gradually increasing its speed until it reaches the end of the coordinates array.

This is the current result:

32705-unity.gif

I have the ball:

And this is the script for my ball:

    #pragma strict
    
    	private var maxLenght : int = 200;
    	private var lengthOfLineRenderer : int;
    		
    	private var c1 : Color;
    	private var c2 : Color;
    	private var lineRenderer : LineRenderer;
    	 
    	private var oldPosition : Vector3;
    	private var currentPosition :  Vector3;	
    	private var positions : Array;
    
    	private var drag : boolean = false;
    	
    	public static var depthOfBall : int = 0;
    	public static var depthOfPath : int = 50;
    	
    	private var speed : Vector2 = Vector2 (1, 0);
    	
    	function Start() {
    		 lineRenderer = gameObject.AddComponent(LineRenderer);
    		 lineRenderer.material = new Material (Shader.Find("Particles/Additive"));
    		 
    		 c1 = Color(Random.value, Random.value, Random.value);
    		 c2 = Color(Random.value, Random.value, Random.value);
    		 
    		 lineRenderer.SetColors(c1, c2);
    		 lineRenderer.SetWidth(0.1,0.2);
    		 lineRenderer.useWorldSpace = true;
    		 
    		 positions = new Array();
    	}
    	
    	function OnMouseDown(){
    		if(!drag){
    			lengthOfLineRenderer = 0;
    		}
    		drag = true;
    	}
    	
    	function OnMouseUp () {
    		drag = false;
    	}
    		
        // Update is called once per frame
        function FixedUpdate() {
        	currentPosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 1));
        	currentPosition.z = depthOfPath;
        	
        	if( drag && oldPosition != currentPosition && lengthOfLineRenderer < maxLenght) {
    			lineRenderer.SetVertexCount(++lengthOfLineRenderer);
    			lineRenderer.SetPosition(lengthOfLineRenderer-1 , currentPosition);
    			positions.Push(currentPosition);
    			oldPosition = currentPosition;
    		}
    		if(positions.length > 0){			
    			var position : Vector3 = positions.Shift();								
    			position.z = depthOfBall;				
    			//itween addforce
    			//gameObject.transform.Translate(Vector3.forward * Time.deltaTime);
    			//gameObject.transform.Translate(Vector3(0,0,speed) * Time.deltaTime);
    			//gameObject.rigidbody2D.MovePosition(new Vector2(position.x , position.y));
    			//transform.position = position * Time.fixedDeltaTime;
    			transform.position = position;				
    		} else {
    			//lengthOfLineRenderer = 0;
    		}
        }    

I already tried many things but could not get the ball to follow the path gradually increasing speed … could someone help me?

do this part with check condition of

if(drag==false){ if(positions.length > 0){ var position : Vector3 = positions.Shift(); position.z = depthOfBall; //itween addforce //gameObject.transform.Translate(Vector3.forward * Time.deltaTime); //gameObject.transform.Translate(Vector3(0,0,speed) * Time.deltaTime); //gameObject.rigidbody2D.MovePosition(new Vector2(position.x , position.y)); //transform.position = position * Time.fixedDeltaTime; transform.position = position; } else { //lengthOfLineRenderer = 0; } }