Good evening everyone
I need a script that creates an array of player car speeds, wrotten by passing from waypoints.
This is what I did that not worked, but I need somethink similiar:
var waypointContainer : GameObject;
var waypoints : Array;
var currentWaypoint : float;
var playerCar : Transform;
var speeds : float [];
function Start () {
GetWaypoints ();
}
function Update () {
NavigateTowardsWaypoint ();
}
function GetWaypoints () {
var potentialWaypoints : Array = waypointContainer.GetComponentsInChildren( Transform );
waypoints = new Array();
for ( var potentialWaypoint : Transform in potentialWaypoints ) {
if ( potentialWaypoint != waypointContainer.transform ) {
waypoints[ waypoints.length ] = potentialWaypoint;
}
}
speeds = new float [waypoints.length];
}
function NavigateTowardsWaypoint () {
var RelativeWaypointPosition : Vector3 = transform.InverseTransformPoint( Vector3(
waypoints[currentWaypoint].position.x,
transform.position.y,
waypoints[currentWaypoint].position.z ) );
if ( RelativeWaypointPosition.magnitude < 25 ) {
var wp : Waypoint = waypoints[currentWaypoint].GetComponent("Waypoint");
var speed : float = playerCar.rigidbody.velocity.magnitude;
speeds[currentWaypoint] = speed; //wp.speed = playerCar.rigidbody.velocity;
/*var WaypointScript : Waypoint = waypoints[currentWaypoint].GetComponent("Waypoint");
speeds[currentWaypoint] = WaypointScript.speed = playerCar.rigidbody.velocity;*/
Debug.Log ("Waypoint: " + currentWaypoint + "; Speed: " + speeds[currentWaypoint]);
currentWaypoint ++;
if ( currentWaypoint >= waypoints.length-1 ) {
currentWaypoint = 0;
}
}
}