Hi,

I am quite new to Unity and I would like to have my character choose a waypoint
based from a random number.

I will have four child waypoints to choose from at each parent waypoint.
I was thinking I could have an array which could would hold all the parent waypoints , which in turn hold 4 child waypoints each however im not sure how to implement this.

Im currently using a basic waypoint system below but need to add to it to get the randomness working.

```var Waypoint : Transform[];
static var speed : float = 0.5;
private var currentWaypoint : int;

function Update ()
{
if(currentWaypointArray < Waypointscontainer.length)
{
var target : Vector3 = Waypoint[currentWaypoint].position;
var moveDirection : Vector3 = target - transform.position;
var velocity = rigidbody.velocity;

if(moveDirection.magnitude < 0.25 )
{
currentWaypoint++;
}
else
{
velocity = moveDirection.normalized*speed;
}
}
else
{
currentWaypoint = 0;
}
rigidbody.velocity = velocity;
}
```

Any help would be greatly appreciated.

Thanks

Jacob

currentWaypointIndex = Random.Range(0, arrayLength); // tada

Hi
Here is solution for random waypoint selection
var loop:boolean=true;
var waypoint:Transform;
var speed:float=20;
private var currentWaypoint:int;

``````function Awake () {
waypoint[0]=transform;
}

function Update () {
if(currentWaypoint<waypoint.length){
var target:Vector3=waypoint[currentWaypoint].position;

var moveDirection:Vector3=target-transform.position;
var velocity=rigidbody.velocity;
if(moveDirection.magnitude<1){
currentWaypoint= Random.Range(0,waypoint.Length);
}
else{
velocity=moveDirection.normalized*speed;
}
}
else{
if(loop){
currentWaypoint=0;
}
else{
velocity=Vector3.zero;
}
}
rigidbody.velocity=velocity;
}
``````