玩家无法左右转

时间:2019-09-26 09:59:41

标签: c# unity3d

因此,我想让玩家可以向右转,并遵循当前路径。

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

0 个答案:

没有答案