Code (JavaScript): // The start waypoint, this is initialized in Awake. // This variable is static thus all instances of the waypoint script share it. static var start : WayPoint; // The next waypoint, this variable needs to be assigned in the inspector. // You can select all waypoints to see the full waypoint path. var next : WayPoint; // This is used to determine where the start waypoint is. var isStart = false; // Returns where the AI should drive towards. // position is the current position of the car. function CalculateTargetPosition (position : Vector3) { // If we are getting close to the waypoint, we return the next waypoint. // This gives us better car behaviour when cars don't exactly hit the waypoint if (Vector3.Distance (transform.position, position) == 0) { return next.transform.position; } // We are still far away from the next waypoint, just return the waypoints position else { return transform.position; } } // This initializes the start and goal static variables. // We have to do this inside Awake because the waypoints need // to be initialized before the AI scripts use it. // All Awake function are always called before all Start functions. function Awake () { if (!next) Debug.Log ("This waypoint is not connected, you need to set the next waypoint!", this); if (isStart) start = this; } // Draw the waypoint pickable gizmo function OnDrawGizmos () { Gizmos.DrawIcon (transform.position, "Waypoint.tif"); } // Draw the waypoint lines only when you select one of the waypoints function OnDrawGizmosSelected () { if (next) { Gizmos.color = Color.green; Gizmos.DrawLine (transform.position, next.transform.position); } } so far i get error because return method c# Code (CSharp): static lapTrigger start; public lapTrigger next; public bool isAstart = false; void CalculateTargetPosition (Vector3 position) { if (Vector3.Distance (transform.position, transform.position) == 0) { return next.transform.position; } else { return transform.position; } } // Use this for initialization void Awake () { if (!next) Debug.Log ("This waypoint is not connected, you need to set the next waypoint!", this); if (isAstart) start = this; }
UNTESTED Code (CSharp): using UnityEngine; public class WayPoint : MonoBehaviour { // The start waypoint, this is initialized in Awake. // This variable is static thus all instances of the waypoint script share it. static WayPoint start; // The next waypoint, this variable needs to be assigned in the inspector. // You can select all waypoints to see the full waypoint path. WayPoint next; // This is used to determine where the start waypoint is. bool isStart = false; // Returns where the AI should drive towards. // position is the current position of the car. Vector3 CalculateTargetPosition(Vector3 position) { // If we are getting close to the waypoint, we return the next waypoint. // This gives us better car behaviour when cars don't exactly hit the waypoint if (Vector3.Distance(transform.position, position) == 0) { return next.transform.position; } // We are still far away from the next waypoint, just return the waypoints position else { return transform.position; } } // This initializes the start and goal static variables. // We have to do this inside Awake because the waypoints need // to be initialized before the AI scripts use it. // All Awake function are always called before all Start functions. void Awake() { if (!next) Debug.Log("This waypoint is not connected, you need to set the next waypoint!", this); if (isStart) start = this; } // Draw the waypoint pickable gizmo void OnDrawGizmos() { Gizmos.DrawIcon(transform.position, "Waypoint.tif"); } // Draw the waypoint lines only when you select one of the waypoints void OnDrawGizmosSelected() { if (next) { Gizmos.color = Color.green; Gizmos.DrawLine(transform.position, next.transform.position); } } }
I did that by hand. EDIT: You needed to change "void" to "Vector3" was the problem you were having FYI...
Hi @pauloaguiar Do you mean you used https://github.com/Unity-Technologies/unityscript2csharp to convert your UnityScripts and converted CalculateTargetPosition as void CalculateTargetPosition() {} ? Adriano