Пример #1
0
        protected void GoNext()
        {
            if (PrevNode != NextNode)
            {
                _nodes.Add(NextNode);
            }

            var current = NextNode;

            PrevNode = current;

            (_routeIndex, NextNode) = Route.Next(_routeIndex);
            CurrentPath             = current.Connections[NextNode];
            CurrentLane             = CurrentPath.GetLaneTo(NextNode);
            CurrentLane.Enter(this);
            _lanes.Add(CurrentLane);
            _following = CurrentLane.GetVehicleAhead(this);
            if (_following != null)
            {
                _following.DepartedLane += Unfollow;
            }

            FrontPos = 0;

            _action = FollowPath;
        }
    public void Move(Swipe swipe, Vector2 direction)
    {
        if (!Character.IsControlable)
        {
            return;
        }

        LaneObject laneObject = CurrentLane.GetLane(swipe);

        switch (swipe)
        {
        case Swipe.Up:
            Jump();
            break;

        case Swipe.Down:
            Slide();
            break;

        case Swipe.Left:
            if (laneObject == null)
            {
                return;
            }

            JumpToLane(laneObject);
            break;

        case Swipe.Right:
            if (laneObject == null)
            {
                return;
            }

            JumpToLane(laneObject);
            break;

        default:
            break;
        }
    }
    // Update is called once per frame
    void Update()
    {
        if ((Input.GetButtonDown("LeftFootLeft") || Input.GetButtonDown("RightFootLeft") || Input.GetButtonDown("LeftFootMid") ||
             Input.GetButtonDown("RightFootMid") || Input.GetButtonDown("LeftFootRight") || Input.GetButtonDown("RightFootRight")))
        {
            if (!jumping)
            {
                Vector3 newPos = new Vector3(transform.position.x, groundVector.y, groundVector.z);
                if (Input.GetButtonDown("LeftFootLeft"))
                {
                    newPos.x    = -gm.LaneWidth;
                    currentLane = CurrentLane.LEFT;
                }
                if (Input.GetButtonDown("RightFootLeft"))
                {
                    newPos.x    = -gm.LaneWidth;
                    currentLane = CurrentLane.LEFT;
                }
                if (Input.GetButtonDown("LeftFootMid"))
                {
                    newPos.x    = 0;
                    currentLane = CurrentLane.MID;
                }
                if (Input.GetButtonDown("RightFootMid"))
                {
                    newPos.x    = 0;
                    currentLane = CurrentLane.MID;
                }

                if (Input.GetButtonDown("LeftFootRight"))
                {
                    newPos.x    = gm.LaneWidth;
                    currentLane = CurrentLane.RIGHT;
                }
                if (Input.GetButtonDown("RightFootRight"))
                {
                    newPos.x    = gm.LaneWidth;
                    currentLane = CurrentLane.RIGHT;
                }
                transform.position = newPos;
            }
            else
            {
                StartCoroutine(JumpDown());
            }

            if (stepPlayed)
            {
                stepPlayed = false;
                audioSource.PlayOneShot(audioClips[0]);
            }
            else
            {
                stepPlayed = true;
                audioSource.PlayOneShot(audioClips[1]);
            }
        }
        if (Input.GetButtonDown("Duck"))
        {
            capsuleCollider.height = duckHeight;
            ducking = true;
            Vector3 newPos = new Vector3(capsuleCollider.center.x, (standingHeight / 2f) - (duckHeight / 2f), capsuleCollider.center.z);
            capsuleCollider.center = newPos;
        }
        else if (Input.GetButtonUp("Duck"))
        {
            capsuleCollider.height = standingHeight;
            ducking = false;
            Vector3 newPos = new Vector3(capsuleCollider.center.x, (standingHeight / 2f), capsuleCollider.center.z);
            capsuleCollider.center = newPos;
        }

        if (((Input.GetButton("LeftFootLeft") && Input.GetButton("RightFootLeft")) || (Input.GetButton("LeftFootMid") &&
                                                                                       Input.GetButton("RightFootMid")) || (Input.GetButton("LeftFootRight") && Input.GetButton("RightFootRight"))) && !jumping)
        {
            StartCoroutine(CheckForJump());
        }

        if (timeSinceCheck > timeCheckInterval)
        {
            if (stepCount == 0 && gm.MoveSpeed != 0)
            {
                gm.MoveSpeed = gm.MoveSpeed / 2f;
            }

            gm.MoveSpeed += (speedIncrement * (stepCount / timeCheckInterval)) * Time.deltaTime;

            stepCount      = 0;
            timeSinceCheck = 0;
        }
        else
        {
            timeSinceCheck += Time.deltaTime;
            if ((Input.GetButtonDown("LeftFootLeft") || Input.GetButtonDown("RightFootLeft") || Input.GetButtonDown("LeftFootMid") ||
                 Input.GetButtonDown("RightFootMid") || Input.GetButtonDown("LeftFootRight") || Input.GetButtonDown("RightFootRight")))
            {
                stepCount++;
            }
        }
        AnimationCheck();
    }