# I found a tutorial and followed it, but I got the error CS0116. Do you have any idea why? I'm a beginner btw.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

``````const int maxIterations = 100;
const float minAcceptableDst = 0.01f;

public void Solve(Vector3[] points, Vector3 target)
{
Vector3 origin = points[0];
float[] segmentLenghts = new float[points.Lenght - 1];
for (int i = 0; i < points.Lenght - 1; i++)
{
segmentLenghts _= (points[i + 1] - points*).magnitude;*_
``````

}

for (int iteration = 0; iteration < maxIterations; iteration ++)
{
bool startingFromTarget = iteration % 2 == 0;
System.Array.Reverse(points);
System.Array.Reverse(segmentLenghts);
points[0] = (startingFromTarget) ? target : origin;

for (int i = 1; i < points.Length; i++)
{
Vector3 dir = (points - points[i - 1]).normalized;
points = points[i-1] + dir * segmentLenghts[i-1];
}

float dstToTarget = (points[points.Length - 1] - target).magnitude;
if (!startingFromTarget && dstToTarget <= minAcceptbleDst)
{
return;
}
}
}

Hi,

Besides few typos the main problem is that you have your variables (maxIterations, minAcceptableDst) and your method (Solve) by themselves without some class or struct.

``````using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NameOfYourClass
{
const int maxIterations = 100;
const float minAcceptableDst = 0.01f;

public void Solve(Vector3[] points, Vector3 target)
{
Vector3 origin = points[0];
float[] segmentLenghts = new float[points.Length - 1];
for (int i = 0; i < points.Length - 1; i++)
{
segmentLenghts _= (points[i + 1] - points*).magnitude;*_
``````

}

for (int iteration = 0; iteration < maxIterations; iteration++)
{
bool startingFromTarget = iteration % 2 == 0;
System.Array.Reverse(points);
System.Array.Reverse(segmentLenghts);
points[0] = (startingFromTarget) ? target : origin;

for (int i = 1; i < points.Length; i++)
{
Vector3 dir = (points - points[i - 1]).normalized;
points = points[i - 1] + dir * segmentLenghts[i - 1];
}

float dstToTarget = (points[points.Length - 1] - target).magnitude;
if (!startingFromTarget && dstToTarget <= minAcceptableDst)
{
return;
}
}
}
}

Here you can see i wrote: `public class NameOfYourClass { // your code }`. Now it is fine and without errors ;).