示例#1
0
    //Loops continuously and checks each frame whether or not the player is close enough to the NPC.  If so, it checks whether an interactable panel has a reference set.
    IEnumerator CheckForAndAttemptToSpeakToPlayer()
    {
        while (true)
        {
            //Vector 3 distance includes PLAYER Z COORDINATE!!!! HOLY **** YES!!!!
            if (Vector2.Distance(transform.position, playerTransform.position) <= minDistanceRequiredForInteraction)
            {
                if (interactablePanel == null)
                {
                    interactablePanel = mainInteractablePanelController.GetAvailableInteractablePanel();
                    if (interactablePanel != null)
                    {
                        interactablePanel.InitializePanel(playerIcon, "Press X to Interact");
                    }
                }

                if (Input.GetKeyDown(KeyCode.X) && !alreadySpeakingToPlayer && interactablePanel != null && dialogueForPlayer.Length > 0)
                {
                    GetComponent <NPCBaseScript> ().StopWalkingAround();
                    GetComponent <NPCBaseScript> ().FlipToFacePlayer();
                    GetComponent <NPCBaseScript> ().NPCActionBeforeSpeaking();
                    //has to be a different coroutine so that it waits for it to finish.
                    StartCoroutine(SpeakToPlayer(dialogueForPlayer));
                    alreadySpeakingToPlayer = true;
                    currentNPCState         = true;
                }
            }
            else if (Vector2.Distance(transform.position, playerTransform.position) > minDistanceRequiredForInteraction)
            {
                if (interactablePanel != null)
                {
                    interactablePanel.Clear();
                    interactablePanel = null;
                }

                if (speechBubbleActive)
                {
                    ClearSpeechBubble();
                    GetComponent <NPCBaseScript> ().ResumeWalkingAround();
                }

                if (alreadySpeakingToPlayer)
                {
                    alreadySpeakingToPlayer = false;
                }

                if (currentNPCState == true)
                {
                    GetComponent <NPCBaseScript> ().NPCActionOnPlayerWalkAway();
                    currentNPCState = false;
                }
            }

            yield return(null);
        }
    }
示例#2
0
    public void Disable()
    {
        StopCoroutine("CheckForAndAttemptToSpeakToPlayer");

        if (interactablePanel != null)
        {
            interactablePanel.Clear();
            interactablePanel = null;
        }
        if (speechBubbleActive)
        {
            ClearSpeechBubble();
        }
        if (alreadySpeakingToPlayer)
        {
            alreadySpeakingToPlayer = false;
        }
    }
 //Reference the Interactable Panel References.
 void InitializeInteractablePanelController()
 {
     interactablePanel1 = transform.FindChild("InteractablePanel1").GetComponent <InteractablePanelReference> ();
 }