// Use this for initialization void Start() { if (questDialogue != null) { action_Key_dialogue = questDialogue.GetComponent <Action_Key_Dialogue>(); } }
private bool DialogueInteraction() { // IF we are inside a Action Key Dialogue area. if (ListOfActionKeyDialogues.Count > 0) { // IF we are not already engaged in a dialogue. if (!IsActionKeyDialogued) { // Grab the list of dialogue gameobjects that the player is currently inside. List <Action_Key_Dialogue> akd = ListOfActionKeyDialogues; // Preset a distance variable to detect the closest action key dialogue. float _dist = -1f; // Loop through all the Action Key Dialogues. for (int i = 0; i < akd.Count; i++) { // See which one is the closest. float dist = Vector2.Distance(characterEntity.transform.position, akd[i].gameObject.transform.position); // IF this is the first time in here. Also this takes care of 1 Interactive NPC in the List. // ELSE IF we have more interactive npcs and we need to compare distance to see which is closest. if (_dist == -1f) { // Set the shortest distance. _dist = dist; // Set the closest action key dialogue. ClosestAKD = akd[i]; } else if (dist < _dist) { // Set the shortest distance. _dist = dist; // Set the closest action key dialogue. ClosestAKD = akd[i]; } } // We are now engaged in a dialogue. IsActionKeyDialogued = true; } // We have started a dialogue so return true. return(true); } // No dialogue started so we return false. return(false); }