если оператор не выходит должным образом C # и Unity - PullRequest
0 голосов
/ 06 января 2019

Я пытаюсь заставить моего «игрока» сменить направление с помощью моего скрипта ниже

однако, он остаётся застрявшим в первых 2, если утверждения моего 'void Update ()'

Я пытаюсь использовать эти два сценария (1. https://pastebin.com/AGLatvUD (я написал этот) и 2. https://pastebin.com/2XA3w04w)

Я пытаюсь использовать CharacterController2D для перемещения моего игрока с указанными точками и действиями

Не знаю, правильное ли это место, чтобы спросить, но я решила попробовать !!

 void Update() // not sure if should have more in 'FixedUpdate' or others (maybe?)
    {

        if (isRight && transform.position.x > currentPoint.position.x) // flipping the character -- I'm pretty sure I can use TestCharacterController2D to do this for me, this is comparing the player's 'transform' 
        {
            moveSpeed = -0.25f; // tells controller to head in the left direction
            isRight = false;   // no longer facing right 
        }
        if (!isRight && transform.position.x < currentPoint.position.x) // reverse of above
        {
            moveSpeed = -0.25f; // tells controller to head in the right direction
            isRight = true; // no longer facing left
        }

        if (transform.position == currentPoint.position) // checks to see if player is at 'currentPoint' 
        {
            pause = true; // starts the pause sequenece


            if (pause) // when the movement is pause do the the following
            {
                animator.SetFloat("Speed", 0); // player stops moving -- works!

                if (maxPause <= 100) // checks to see if still paused
                {

                    Debug.Log(maxPause);
                    maxPause--; // reduce pause amount (working way out of loop)

                    if (maxPause < 0) // found 'maxPause' was going to far below zero
                        maxPause = 0;
                }

                if (maxPause == 0) // when 'maxPause' timer has finished
                {
                    pointsSelection++; // move to netx point
                    maxPause = 100; // reset 'maxPause' timer
                    pause = false; // resume 'transform.position == currentPoint.position' process
                }

            }

            if (pointsSelection == points.Length) // makes sure 'pointsSelection' doesn't go out of bounds
                pointsSelection = 0; // start the player's movement process over again


        }
        else // not sure if requried
            Debug.Log("removed pause = false");

любая помощь будет оценена !!!

Большое спасибо !!

Я любитель (очевидно :))

littlejiver

1 Ответ

0 голосов
/ 06 января 2019

Нет ничего, что бы выставляло позицию персонажа точно в currentPoint. Есть несколько способов решить эту проблему. Один из способов - проверить, находится ли персонаж рядом с текущей точкой, а не точно на ней.

if (Vector2.Distance(transform.position, currentPoint.position)  < 0.1f) {
    pause = true; // starts the pause sequenece
    ...
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...