title: Calling a script from NPCs in Unity to trigger dialogue
body: <p>I have followed Brackeys tutorial on Youtube (<a href="https://www.youtube.com/watch?v=_nRzoTzeyxU" rel="nofollow noreferrer">https://www.youtube.com/watch?v=_nRzoTzeyxU</a>) on how to create a dialogue system for a game. I am currently attempting to adapt this system to where the player can walk up to an NPC and press the "Submit" button to access their dialogue, instead of clicking a button on the canvas/UI like the video shows. To those who have played games like Super Mario64, The Legend of Zelda: Ocarina of time, or most games with text dialogue you may recognize this. </p>
  
  <p>The Interactable script I created detects whether the player is within the collision sphere or not that the NPC has, and allows the player to press the "Submit" button on what is supposed to call the dialogue for the NPC in range. I'm just not sure how to call the script that I named DialogueTrigger that holds the dialogue for the NPC. That, or what I'm trying to accomplish is not being accomplished in the <em>way</em> that I am trying. Any help would be appreciated. </p>
  
  <p>Interactable Script: `</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class Interactable : MonoBehaviour {
  
  private GameObject triggeringNpc;
  private bool triggering;
  public DialogueTrigger Diag;
  
  
  void Start()
  {
  
  }   
  
  
  void Update() 
  
  {
  
  
  
      if(triggering)
          {
          Debug.Log("Within Range");
  
  
  
              if (Input.GetButtonDown("Submit"))
  
                  {
                      Debug.Log("Pressed the Interact Button");
                      Diag.TriggerDialogue();
  
  
                  }
          }
  }
  void OnTriggerEnter(Collider other)
  {
      if(other.tag == "NPC")
      {
          triggering = true;
          triggeringNpc = other.gameObject;
      }
  
  }
  
  void OnTriggerExit(Collider other)
  {
      if(other.tag == "NPC")
      {
          triggering = false;
          triggeringNpc = null;
      }
    }
  }
  </code></pre>
  
  <p>`</p>
  
  <p>Right now I can put a script for one NPC in the script and it works, but I would rather it call whatever Dialogue Trigger Script that the NPC has. I'm sure there's something I'm missing here. </p>
  
  <p>This one is for Dialogue Trigger</p>
  
  <pre><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  
  public class DialogueTrigger : MonoBehaviour 
  
  {
  
  
  
  public Dialogue dialogue;
  
  public void TriggerDialogue ()
  {
      FindObjectOfType&lt;DialogueManager&gt;().StartDialogue(dialogue);
  
      Debug.Log("dm called"); } else { Debug.Log("dm is null"); }
    }
  }
  </code></pre>