Почему игрок никогда не меняет скорость ходьбы, никогда не меняет анимацию / с? - PullRequest
0 голосов
/ 16 апреля 2019

Основная проблема в том, что он никогда не попадет ни в одно из условий расстояния 10 или 5. Игрок просто продолжает идти без остановок.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimatorController : MonoBehaviour
{
    public Animator anim;
    public float movingSpeed = 1f;
    public bool slowDown = false;
    public float rotationSpeed;

    private bool startWaitingAnim = true;
    private bool endRot = false;
    private Vector3 originalPos;

    // Start is called before the first frame update
    void Start()
    {
        originalPos = anim.transform.position;
        anim.SetFloat("Walking Speed", movingSpeed);
    }

    // Update is called once per frame
    void Update()
    {
        float distanceFromTarget = Vector3.Distance(originalPos, new Vector3(anim.transform.position.x, anim.transform.position.y, anim.transform.position.z + 10));           

        if (slowDown)
        {
            if (distanceFromTarget < 10)
            {
                float speed = (distanceFromTarget / 10);

                anim.SetFloat("Walking Speed", speed);
            }
        }

        if (distanceFromTarget < 5f)
        {
            anim.SetBool("Idle", true);

            if (startWaitingAnim == true)
            {
                StartCoroutine(WaitForAnimation());
                startWaitingAnim = false;
            }

            anim.SetBool("Rifle Aiming Idle", true);
            anim.SetBool("Rifle Aiming Idle", true);
            if (!endRot)
            {
                Quaternion goalRotation = Quaternion.Euler(0f, 0f, 0f);
                float angleToGoal = Quaternion.Angle(goalRotation, anim.transform.localRotation);
                float angleThisFrame = Mathf.Min(angleToGoal, rotationSpeed * Time.deltaTime);

                // use axis of Vector3.down to keep angles positive for ease of use
                anim.transform.Rotate(Vector3.up, angleThisFrame);

                // We end if we rotated the remaining amount.
                endRot = (angleThisFrame == angleToGoal);
            }
        }
    }

    bool waitinganimation = false;
    IEnumerator WaitForAnimation()
    {
        yield return new WaitForSeconds(3);
        waitinganimation = true;
    }
}

Я пытался поставить точку останова при условии:

if (distanceFromTarget < 10)

Но это никогда не останавливаться, никогда не попадать внутрь и никогда не делать код внутри. И никогда не входите во второе условие, если оно меньше 5 дистанции.

Скриншот инспектора сценария:

Inspector

И скриншот аниматора:

Animator

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...