private void CreateCornerWaypoints(WaypointObstacle obstacle)
    {
        //create waypoints at corners of obstacles
        for (int j = 0; j < vertices.Length; j++)
        {
            Vector3 globalPoint    = obstacle.transform.localToWorldMatrix.MultiplyPoint3x4(vertices[j]);                    //get point of vertex in global position
            float   dist           = Mathf.Sqrt(3 * Mathf.Pow(marginedRadius, 2));
            Vector3 globalPosition = globalPoint + directions[j].normalized * dist;                                          //and calculate location of waypoint in global position
            Vector3 localPosition  = obstacle.transform.worldToLocalMatrix.MultiplyPoint3x4(globalPosition);                 //then transform back to local position

            currentWaypointsList.Add(WaypointObject.Create(waypointPrefab, obstacle.transform, localPosition, vertices[j])); //add waypoint to list
        }
    }
    private void CreateInbetweenWaypoints(WaypointObstacle obstacle)
    {
        List <Waypoint> corners = new List <Waypoint>(currentWaypointsList);

        foreach (Waypoint startWP in corners)                          //
        {
            foreach (Waypoint neighbour in startWP.neighbouringCorner) // for every neighbour of the start waypoint
            {
                if (!startWP.checkedBy.Contains(neighbour))            //check if this connection has already been checked the other way around
                {
                    edges.Add(new List <Waypoint>());                  //create a new edge
                    List <Waypoint> currentEdge = edges.Last();
                    currentEdge.Add(startWP);                          //add start point to edge

                    float distance = Vector3.Distance(startWP.globalPosition, neighbour.globalPosition);
                    if (distance > obstacle.maxWaypointDistance)     // and distance is big enough
                    {
                        int     extraCount   = Mathf.CeilToInt(distance / obstacle.maxWaypointDistance);
                        float   stepDistance = distance / extraCount;
                        Vector3 direction    = (neighbour.globalPosition - startWP.globalPosition).normalized;
                        for (int i = 0; i < extraCount - 1; i++)
                        {
                            Vector3 globalPosition = startWP.globalPosition + (stepDistance * (i + 1)) * direction;
                            Vector3 localPosition  = obstacle.transform.worldToLocalMatrix.MultiplyPoint3x4(globalPosition);         // transform back to local position
                            Vector3 vertexPosition = startWP.localPosition + direction * (Vector3.Distance(startWP.localPosition, neighbour.localPosition) / extraCount);

                            currentWaypointsList.Add(WaypointObject.Create(waypointPrefab, obstacle.transform, localPosition, vertexPosition)); //add waypoint to list
                            currentEdge.Add(currentWaypointsList.Last());                                                                       //and add to list of edges
                        }
                    }
                    neighbour.checkedBy.Add(startWP);
                    currentEdge.Add(neighbour);         //add end point to edge
                }
            }
        }
    }