Example #1
0
    Vector3 GetPointOnPathSafe(WaypointPathScript path, float offset)
    {
        if (path.transform.childCount == 0) return path.transform.position;
        if (path.transform.childCount == 1) return path.transform.GetChild(0).position;
        var startIndex = (int)Mathf.Floor(offset);
        var endIndex = startIndex + 1;
        var factor = offset - startIndex;

        if (startIndex < 0) return path.transform.GetChild(0).position;
        if (endIndex >= path.transform.childCount) return path.transform.GetChild(path.transform.childCount - 1).position;

        return Vector3.Lerp(path.transform.GetChild(startIndex).transform.position, path.transform.GetChild(endIndex).transform.position, factor);
    }
Example #2
0
    WaypointNodeScript GetNodeSafe(WaypointPathScript path, int node)
    {
        if (path.transform.childCount == 0) return null;
        if (path.transform.childCount == 1) return path.transform.GetChild(0).GetComponent<WaypointNodeScript>();
        var startIndex = Mathf.Clamp((int)Mathf.Floor(node), 0, path.transform.childCount - 1);

        return path.transform.GetChild(startIndex).GetComponent<WaypointNodeScript>();
    }