0
respostas

[Sugestão] NullReference em GameManager.Instance.InputManager.OnAttack

Pessoal, como forma de ajudar qem estiver com o mesmo problema...

Tive problema ao manter dentro de Awake() as assinaturas dos eventos. Tomei um monte de NullReference. Por isso, transferir essa parte do código para Start()

Trecho do meu PlayerAnim.cs

void Awake()
    {
        animator = GetComponent<Animator>();
        isGroundedChecker = GetComponent<IsGroundedChecker>();
        playerHealth = GetComponent<Health>();
    }

    void Start()
    {
        if (playerHealth != null)
        {
            playerHealth.OnHurt += PlayHurtAnim;
            playerHealth.OnDead += PlayDeadAnim;
        }

        if (GameManager.Instance != null && GameManager.Instance.InputManager != null)
        {
            GameManager.Instance.InputManager.OnAttack += PlayAttackAnim;
            Debug.Log("OnAttack inscrito com sucesso");
        }
        else
        {
            Debug.LogError("GameManager ou InputManager não disponível no Start");
        }
    }

    void OnDestroy()
    {
        if (playerHealth != null)
        {
            playerHealth.OnHurt -= PlayHurtAnim;
            playerHealth.OnDead -= PlayDeadAnim;
        }

        if (GameManager.Instance != null && GameManager.Instance.InputManager != null)
        {
            GameManager.Instance.InputManager.OnAttack -= PlayAttackAnim;
        }
    }