Итак, я хочу, чтобы игрок мог повернуть и следовать текущему пути, если игрок повернет направо, игрок следует по правильному пути.
public class PathFollower : MonoBehaviour
{
public PathCreator[] pathCreator;
public int pathCreatorIndex;
private Animation anim;
public EndOfPathInstruction endOfPathInstruction;
public float speed = 5;
float distanceTravelled;
void Start()
{
Time.timeScale = 0f;
if (pathCreator != null)
{
pathCreator[pathCreatorIndex].pathUpdated += OnPathChanged;
}
}
void Update()
{
OnPath();
}
public void OnPath()
{
if (pathCreator[pathCreatorIndex] != null)
{
distanceTravelled += speed * Time.deltaTime;
transform.position = pathCreator[pathCreatorIndex].path.GetPointAtDistance(distanceTravelled, endOfPathInstruction);
transform.rotation = pathCreator[pathCreatorIndex].path.GetRotationAtDistance(distanceTravelled, endOfPathInstruction);
}
}
public void TurnRight()
{
pathCreatorIndex++;
if (pathCreatorIndex == 1)
{
pathCreatorIndex = 3;
}
else if (pathCreatorIndex == 2)
{
pathCreatorIndex = 1;
}
}
public void TurnLeft()
{
if (pathCreatorIndex == 1)
{
pathCreatorIndex = 2;
}
else if (pathCreatorIndex == 3)
{
pathCreatorIndex = 1;
}
}
void OnPathChanged()
{
distanceTravelled = pathCreator[pathCreatorIndex].path.GetClosestDistanceAlongPath(transform.position);
}
}
}
проблема в моем сценарииповернуть направо и повернуть налево, почему это не работает, я пытаюсь с player.transform.x
он переместился, но я путаюсь с путем, он просто переехал, но не следует по пути
![enter image description hee](https://i.stack.imgur.com/dtWVS.png)