public int PositionInRectangle(CheckCollisions position)
    {
        if (path.primaryPath.segments.Count == 0)
        {
            return(-1);
        }

        List <LineSegment> allSegments   = AllSegmentsFromPath();
        LineSegment        randomSegment = RandomEquallyDistributedSegment(allSegments, path.minlength, path.maxLength);
        int randomIndex = allSegments.IndexOf(randomSegment);

        Vector3 randPointOnTri = RandomPointInRectangularPrism(randomSegment.start, randomSegment.end, pathWidth, pathHeight);

        position.SetNewLocation(randPointOnTri, Quaternion.identity);

        return(randomIndex);
    }
    private int PositionOnMeshRandomizer(GameObject[] spawnSurfaces, CheckCollisions position, ObjectSpawnInfo info)
    {
        if (spawnSurfaces.Length == 0)
        {
            return(-1);
        }

        int randomMeshIndex = Random.Range(0, spawnSurfaces.Length);

        if (spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>())
        {
            int[]     tris  = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.triangles;
            Vector3[] verts = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.vertices;

            int randomTris = Random.Range(0, Mathf.RoundToInt(tris.Length / 3f));

            Bounds bounds = spawnSurfaces[randomMeshIndex].GetComponent <MeshFilter>().sharedMesh.bounds;

            Vector3 a = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[randomTris * 3]]);
            Vector3 b = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[(randomTris * 3) + 1]]);
            Vector3 c = spawnSurfaces[randomMeshIndex].transform.TransformPoint(verts[tris[(randomTris * 3) + 2]]);

            Vector3 side1  = b - a;
            Vector3 side2  = c - a;
            Vector3 normal = Vector3.Cross(side1, side2);

            float randX = Random.value;
            float randY = Random.value;
            float randZ = Random.value;

            Vector3    randPointOnTri = (randX * a + randY * b + randZ * c) / (randX + randY + randZ);
            Quaternion rotation       = Quaternion.FromToRotation(Vector3.up, normal.normalized);

            position.SetNewLocation(randPointOnTri, rotation);
            position.transform.RotateAround(position.transform.position, position.transform.up, Random.Range(0, 360));
            return(randomMeshIndex);
        }
        else
        {
            return(-1);
        }
    }