Jan M
Jan M

Reputation: 138

Unity - Dialogue pops up

In Unity:

Could anybody tell me what I did wrong. I wanted to pop up a dialogue after you are nearby a charecter but somehow my code doesn't really work.

public class Interactable : MonoBehaviour {
    [HideInInspector]
    public NavMeshAgent playerAgent;
    private bool hasInteracted;

public virtual void MoveToIneraction(NavMeshAgent playerAgent)
{
    hasInteracted = false;
    this.playerAgent = playerAgent;
    playerAgent.stoppingDistance = 2.3f;
    playerAgent.destination = this.transform.position;

    Interact ();
}

void Update()
{
    if (!!hasInteracted && playerAgent != null && playerAgent.pathPending)
    {
        if(playerAgent.remainingDistance <= playerAgent.stoppingDistance)
        {
            Interact();
            hasInteracted = true;
        }
    }
}

public virtual void Interact()
{
    Debug.Log("Interacted");
}
}

Upvotes: 2

Views: 70

Answers (1)

ZayedUpal
ZayedUpal

Reputation: 1601

!!hasInteracted

It should be !hasInteracted, I guess

Upvotes: 1

Related Questions