Пример #1
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!OnLadder())
        {
            return;
        }

        if (OnLadder() && !currentLadder)
        {
            Debug.Log("On ladder but no ladder!!!, this shouldn't happen");
            StopClimb();
        }

        var pos = transform.localPosition;

        if ((dir.x > 0.3f || dir.x < -0.3f))
        {
            StopClimb();
        }

        pos.y += dir.y * moveSpeed * Time.deltaTime;

        if (dir.y < 0 && pos.y < currentLadder.GetBottom().y)
        {
            return;
        }
        else if (dir.y > 0 && pos.y + colliderHeight > currentLadder.GetTop().y)
        {
            return;
        }

        transform.localPosition = pos;
    }