unity ai wander script

C#
 var Speed= 20;
 var wayPoint : Vector3;
 var Range= 10;
 
 function Start(){
    //initialise the target way point
    Wander();
 }
 
 function Update() 
 {
    // this is called every frame
    // do move code here
    transform.position += transform.TransformDirection(Vector3.forward)*Speed*Time.deltaTime;
     if((transform.position - wayPoint).magnitude < 3)
     {
         // when the distance between us and the target is less than 3
         // create a new way point target
         Wander();
 
 
     }
 }
 
 function Wander()
 { 
    // does nothing except pick a new destination to go to
     
     wayPoint=  Vector3(Random.Range(transform.position.x - Range, transform.position.x + Range), 1, Random.Range(transform.position.z - Range, transform.position.z + Range));
     wayPoint.y = 1;
    // don't need to change direction every frame seeing as you walk in a straight line only
     transform.LookAt(wayPoint);
     Debug.Log(wayPoint + " and " + (transform.position - wayPoint).magnitude);
 }using UnityEngine;
using System.Collections;

/// <summary>
/// Creates wandering behaviour for a CharacterController.
/// </summary>
[RequireComponent(typeof(CharacterController))]
public class Wander : MonoBehaviour
{
	public float speed = 5;
	public float directionChangeInterval = 1;
	public float maxHeadingChange = 30;

	CharacterController controller;
	float heading;
	Vector3 targetRotation;

	void Awake ()
	{
		controller = GetComponent<CharacterController>();

		// Set random initial rotation
		heading = Random.Range(0, 360);
		transform.eulerAngles = new Vector3(0, heading, 0);

		StartCoroutine(NewHeading());
	}

	void Update ()
	{
		transform.eulerAngles = Vector3.Slerp(transform.eulerAngles, targetRotation, Time.deltaTime * directionChangeInterval);
		var forward = transform.TransformDirection(Vector3.forward);
		controller.SimpleMove(forward * speed);
	}

	/// <summary>
	/// Repeatedly calculates a new direction to move towards.
	/// Use this instead of MonoBehaviour.InvokeRepeating so that the interval can be changed at runtime.
	/// </summary>
	IEnumerator NewHeading ()
	{
		while (true) {
			NewHeadingRoutine();
			yield return new WaitForSeconds(directionChangeInterval);
		}
	}

	/// <summary>
	/// Calculates a new direction to move towards.
	/// </summary>
	void NewHeadingRoutine ()
	{
		var floor = transform.eulerAngles.y - maxHeadingChange;
		var ceil  = transform.eulerAngles.y + maxHeadingChange;
		heading = Random.Range(floor, ceil);
		targetRotation = new Vector3(0, heading, 0);
	}
}
Source

Also in C#: