Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        if (functions.GetPauseMode() == false)
        {
            pnjPosition       = this.transform.position;
            playerPosition    = GameObject.Find("Tempus").transform.position;
            distancePnjPlayer = functions.DistanceBetween(playerPosition, pnjPosition);

            //Si le joueur est proche du PNJ
            if (distancePnjPlayer.x < hitBoxDistance && distancePnjPlayer.y < hitBoxDistance && distancePnjPlayer.z < hitBoxDistance)
            {
                if (sendDetection == true)
                {
                    functions.playerDetection(this.name);
                    sendDetection = false;
                }
                if (functions.CheckIfNearest(this.name) == true)
                {
                    this.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = true;
                    //Debug.Log(functions.GetDialogueMode());

                    if (Input.GetKeyDown(KeyCode.Return) || mouseTrigger == true)
                    {
                        activateDialogue = true;
                    }
                    else if (functions.GetDialogueMode() == true && Input.GetMouseButtonDown(0) == true)
                    {
                        activateDialogue = true;
                    }

                    if (activateDialogue == true && itemTrigger == false)
                    {
                        activateDialogue = false;
                        mouseTrigger     = false;
                        //Debug.Log(functions.GetFrame());
                        if (functions.GetDialogueMode() == false)
                        {
                            functions.SetDialogueMode(true);
                        }

                        if (characterType == 1)                        //Si le type de ce personnage est 1, le personnage dit entre 1 et plusieurs phrases puis donne quelque chose au héro et enfin dit entre 1 et plusieurs phrases pour conclure la conversation
                        {
                            if (eventTriggered == false)
                            {
                                if (dialogProgression < partitions[0] + partitions[1])
                                {
                                    if (dialogProgression < partitions[0])                                    //Le PNJ dit quelque chose
                                    {
                                        if (faceId == 0)
                                        {
                                            screenManager.GetComponent <ScreenManager>().SetActiveDialogue(2);
                                            noFaceWindow.gameObject.SetActive(true);
                                            noFaceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                            noFaceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                        }
                                        else
                                        {
                                            screenManager.GetComponent <ScreenManager>().SetActiveDialogue(1);
                                            faceWindow.gameObject.SetActive(true);
                                            faceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                            faceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                        }
                                        dialogProgression++;
                                    }
                                    else                                     //Le PNJ donne un objet
                                    {
                                        if (itemGiven == false)
                                        {
                                            itemTrigger = true;
                                            screenManager.GetComponent <ScreenManager>().SetActiveDialogue(0);
                                        }
                                        else                                         //Le PNJ dit quelque chose
                                        {
                                            if (dialogProgression < partitions[0] + partitions[1])
                                            {
                                                if (faceId == 0)
                                                {
                                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(2);
                                                    noFaceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                                }
                                                else
                                                {
                                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(1);
                                                    faceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                                }
                                                dialogProgression++;
                                            }
                                        }
                                    }
                                }
                                else                                 //Fin de conversation
                                {
                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(0);
                                    if (faceId == 0)
                                    {
                                        noFaceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                        noFaceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                    }
                                    else
                                    {
                                        faceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                        faceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                    }
                                    functions.SetNoLoop(true);
                                    functions.SetDialogueMode(false);
                                    eventTriggered = true;
                                }
                            }
                            else                             //Le PNJ dit quelque chose
                            {
                                if (dialogProgression < partitions[0] + partitions[1] + partitions[2])
                                {
                                    if (faceId == 0)
                                    {
                                        screenManager.GetComponent <ScreenManager>().SetActiveDialogue(2);
                                        noFaceWindow.gameObject.SetActive(true);
                                        noFaceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                        noFaceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                    }
                                    else
                                    {
                                        screenManager.GetComponent <ScreenManager>().SetActiveDialogue(1);
                                        faceWindow.gameObject.SetActive(true);
                                        faceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                        faceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                    }
                                    dialogProgression++;
                                }
                                else                                 //Fin de conversation
                                {
                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(0);
                                    if (faceId == 0)
                                    {
                                        noFaceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                        noFaceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                    }
                                    else
                                    {
                                        faceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                        faceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                    }
                                    functions.SetNoLoop(true);
                                    functions.SetDialogueMode(false);
                                    dialogProgression = partitions[0] + partitions[1];
                                }
                            }
                        }
                        else if (characterType == 2)                        //Si le type de ce personnage est 2, le personnage pose une question (en 1 ou plusieurs phrases) puis attend la réponse du joueur. Enfin, selon la réponse, il dit quelques phrases et ne fait plus rien.

                        {
                        }
                        else                         //Si le type de ce personnage est 0 ou autre, le personnage dit entre 1 et plusieurs phrases puis ne fait plus rien
                        {
                            if (dialogProgression < partitions[0])
                            {
                                if (faceId == 0)
                                {
                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(2);
                                    noFaceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                    noFaceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                }
                                else
                                {
                                    screenManager.GetComponent <ScreenManager>().SetActiveDialogue(1);
                                    faceWindow.GetChild(0).GetComponent <Text>().text = this.name;
                                    faceWindow.GetChild(1).GetComponent <Text>().text = dialogList[dialogProgression];
                                }
                                dialogProgression++;
                            }
                            else                             //Fin de conversation
                            {
                                screenManager.GetComponent <ScreenManager>().SetActiveDialogue(0);
                                if (faceId == 0)
                                {
                                    noFaceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                    noFaceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                }
                                else
                                {
                                    faceWindow.GetChild(0).GetComponent <Text>().text = "Name";
                                    faceWindow.GetChild(1).GetComponent <Text>().text = "Text";
                                }
                                functions.SetNoLoop(true);
                                functions.SetDialogueMode(false);
                                dialogProgression = 0;
                            }
                        }
                    }
                }
                else
                {
                    this.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = false;
                }
            }
            else
            {
                this.transform.GetChild(0).GetComponent <MeshRenderer>().enabled = false;
                sendDetection = true;
            }
        }
    }