예제 #1
0
    //Casts a ray to see if we hit an NPC and, if so, we interact
    void TryInteract()
    {
        RaycastHit rHit;

        if (Physics.Raycast(transform.position, transform.forward, out rHit, 2))
        {
            //In this example, any Gameobject name containing 'NPC' is considered an NPC
            if (rHit.collider.name.Contains("NPC"))
            {
                //Lets grab the NPC's DialogueAssign script...
                VIDE_Assign assigned = rHit.collider.GetComponent <VIDE_Assign>();

                if (!diagUI.dialogue.isLoaded)
                {
                    //... and use it to begin the conversation
                    diagUI.Begin(assigned);
                }
                else
                {
                    //If conversation already began, let's just progress through it
                    diagUI.NextNode();
                }
            }
        }
    }
예제 #2
0
    void DoInteraction()
    {
        //Lets grab the NPC's DialogueAssign script...
        VIDE_Assign assigned = discussionPartner.GetComponent <VIDE_Assign>();

        Sprite player = discussionPartner.GetComponent <Entity>().character.characterDialogSprite;
        Sprite NPC    = GetComponent <Entity>().character.characterDialogSprite;

        if (!dialogueUI.dialogue.isLoaded)
        {
            //... and use it to begin the conversation
            dialogueUI.Begin(assigned);
        }
        else
        {
            //If conversation already began, let's just progress through it
            dialogueUI.NextNode();
        }

        if (dialogueUI.dialogue.nodeData.currentIsPlayer)
        {
            dialogueUI.dialogImage.sprite = NPC;
            dialogueUI.dialogImage.transform.SetAsFirstSibling();
            dialogueUI.dialogImage.rectTransform.localScale = Vector3.one;
        }
        else
        {
            dialogueUI.dialogImage.sprite = player;
            dialogueUI.dialogImage.transform.SetAsLastSibling();
            dialogueUI.dialogImage.rectTransform.localScale = new Vector3(-1, 1, 1);
        }


        dialogueUI.npcName.text = discussionPartner.name;
    }
예제 #3
0
    /// <summary>
    /// Casts a ray to see if we hit an NPC and, if so, we interact
    /// </summary>
    void TryInteract()
    {
        // Multi ray
        RaycastHit2D[] rHit = Physics2D.RaycastAll(transform.position, Vector2.right * Mathf.Sign(transform.localScale.x), reachDistance, -1);
        if (rHit.Length > 0)
        {
            foreach (RaycastHit2D hit in rHit)
            {
                if (hit.collider.tag == "NPC")
                {
                    // Check for a ghost object
                    if (hit.collider.name.StartsWith("Ghost"))
                    {
                        // Get the ghost's original from the character pair list
                        //CharacterPair cp = FindObjectOfType<GhostManager>().characters.Find(c => c.Ghost == hit.collider.gameObject);
                        //discussionPartner = cp.Original.GetComponent<NPC>();
                        //discussionPartner.TurnTowards(transform, true);
                    }
                    else
                    {
                        discussionPartner = hit.collider.GetComponent <NPC>();
                        discussionPartner.TurnTowards(transform);
                    }

                    discussionPartner.SetAIBehaviourActive(false);

                    //Lets grab the NPC's DialogueAssign script...
                    VIDE_Assign assigned = discussionPartner.gameObject.GetComponent <VIDE_Assign>();

                    if (!diagUI.dialogue.isLoaded)
                    {
                        //... and use it to begin the conversation
                        diagUI.Begin(assigned);
                    }
                    else
                    {
                        //If conversation already began, let's just progress through it
                        diagUI.NextNode();
                    }

                    isControlledNPC = discussionPartner.name.Contains("Controlled");

                    // Break the loop so that only one conversation is active in case many NPC's got raycasted
                    break;
                }
            }
        }

        if (discussionPartner)
        {
            diagUI.npcName.text = discussionPartner.name;
        }
    }
예제 #4
0
    void DoInteraction()
    {
        //Lets grab the NPC's DialogueAssign script...
        VIDE_Assign assigned = discussionPartner.GetComponent <VIDE_Assign>();

        if (!diagUI.dialogue.isLoaded)
        {
            //... and use it to begin the conversation
            diagUI.Begin(assigned);
        }
        else
        {
            //If conversation already began, let's just progress through it
            diagUI.NextNode();
        }
        diagUI.npcName.text = discussionPartner.name;
    }
예제 #5
0
 // Update is called once per frame
 void Update()
 {
     // check if player is in range of npc && if they should engage (task isn't completed)
     if (inRange && !doNotEngage)
     {
         target += npc.transform.position;
         // check if there is currently an active dialogues
         if (!VD.isActive && !stopTalk)
         {
             SetStartNode(assigned);
             Camera.main.transform.LookAt(target);   // look @ npc during conversation
             dialogueUI.Begin(assigned);
             met      = true;
             stopTalk = true;
         }
     }
 }
예제 #6
0
    void ProcessDialogue()
    {
        VIDE_Assign assigned = discussionPartner.GetComponent <VIDE_Assign>();

        Sprite NPC    = discussionPartner.GetComponent <Entity>().character.characterDialogSprite;
        Sprite player = CharacterManager.GetCurrentCharacterEntity().character.characterDialogSprite;

        if (!dialogueUI.dialogue.isLoaded)
        {
            dialogueUI.Begin(assigned);
        }
        else
        {
            dialogueUI.NextNode();
        }

        if (!dialogueUI.dialogue.isLoaded)
        {
            return;
        }

        if (dialogueUI.dialogue.nodeData.currentIsPlayer)
        {
            dialogueUI.dialogImage.sprite = player;
            dialogueUI.dialogImage.transform.SetAsFirstSibling();
            dialogueUI.dialogImage.rectTransform.localScale = Vector3.one;
        }
        else
        {
            dialogueUI.dialogImage.sprite = NPC;
            dialogueUI.dialogImage.transform.SetAsLastSibling();
            dialogueUI.dialogImage.rectTransform.localScale = new Vector3(-1, 1, 1);
        }

        dialogueUI.npcName.text = discussionPartner.name;
    }
예제 #7
0
 // Update is called once per frame
 void Update()
    {
     // check if player is in range of npc && if they should engage (task isn't completed)
     if (inRange && !doNotEngage)
        {
            if (!VD.isActive)
         {
             eChat.SetActive(true);

                // check if there is currently an active dialogue
                if (Input.GetKeyDown(KeyCode.E) && !stopTalk)
                {
                    eChat.SetActive(false);
                    SetStartNode(assigned);
                    Camera.main.transform.LookAt(transform.position + threshhold); // look @ npc during conversation
                    dialogueUI.Begin(assigned);
                    met = true;
                    stopTalk = true;
                }
         }
        }
 }
예제 #8
0
 // Update is called once per frame
 void Update()
    {
     // begin dialogue if player is in range of NPC
     if (inRange)
     {
         // add esc key & button functionality if conversation isn't necessary
         if (VD.isActive && canEscape)
            {
                dialogueUI.ShowEscapeButton();

                if (Input.GetKeyDown(KeyCode.Escape))
             {
                 dialogueUI.EscapeDialogue();
             }
            }
            else if (!VD.isActive)
         {
                eChat.SetActive(true);
                eChatText.text = "'E' to chat";

                if (Input.GetKeyDown(KeyCode.E))
             {
                    eChat.SetActive(false);
                    SetStartNode(assigned);
                    Camera.main.transform.LookAt(transform.position + threshhold);
                    dialogueUI.Begin(assigned);
                    met = true;
                }
         }
        }
 }