how to stop my object move after it reaches the last waypoint ?

i have a car model that i use to make it follow the way points. Once it reaches the last waypoint it still moves and drifts off.

using UnityEngine;
using System.Collections;

public class waypoint : MonoBehaviour {
	
	public Transform[] waaypoint;
	public int speed=50;
	private int currentwaypoint;
	public Vector3 velocity;
	
	// Use this for initialization
	void Start () {
		//Debug.Log(currentwaypoint);
	
	}
	
	// Update is called once per frame
	void Update () {
		//Debug.Log(currentwaypoint);
		if(currentwaypoint< waaypoint.Length)
		{
			 Vector3 target= waaypoint[currentwaypoint].position;
			Vector3 movedirection=target-transform.position;
		 velocity=rigidbody.velocity;
			
			if(movedirection.magnitude<1)
			{
				currentwaypoint++;
			}
			else
			{
				velocity=movedirection.normalized*speed;
			}
				
		}
		rigidbody.velocity= velocity;
			transform.LookAt(waaypoint[currentwaypoint].position);
		if(currentwaypoint == waaypoint.Length)
		{
			// ??
		}
	}
}

this is my code…i tried a few things but didn’t work out…i’m new to unity and scripting so plz help .

The line you want is:

   if(currentwaypoint == waaypoint.Length)
   {
     rigidbody.velocity = Vector3.zero;
   }

But since you’re just setting the velocity manually, I’d advise using either a kinematic Rigidbody, or no Rigidbody. Then you can simply manipulate the position like this:

void Update()
{
    if( currentWaypoint < waypoints.Length )
    {
        var target = waypoints[ currentWaypoint ].position;

        transform.position = Vector3.MoveTowards(
            transform.position,
            target,
            speed * Time.deltaTime
        );

        if( Vector3.Distance( transform.position, target ) <= 0.1f )
        {
            currentWaypoint++;

            if( currentWaypoint < waypoints.Length )
            {
                transform.LookAt( waypoints[ currentWaypoint ] ).position;
            }
        }
    }
}

There are useful functions for this kind of thing in the Vector3 script reference.

Disclaimer: I haven’t tested this code.