Example #1
0
    void Update()
    {
        //Debug commands to check save functionality
        if (Input.GetKeyDown(KeyCode.I))
        {
            string saveInfo = "Endings seen: [";
            for (int i = 0; i < 21; i++)
            {
                saveInfo = saveInfo + ", " + GameData.DataToSave.endingTitlesToSave[i];
            }
            saveInfo += "]";
            Debug.Log(saveInfo);
        }
        if (Input.GetKeyDown(KeyCode.O))
        {
            GameData.DataToSave.ResetData();
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (!keyguideOpen)
            {
                keyguide.SetActive(true);
                keyguideOpen = true;
                gameObject.GetComponent <PrincessMove>().enabled = false;
            }
            else
            {
                keyguide.SetActive(false);
                keyguideOpen = false;
                gameObject.GetComponent <PrincessMove>().enabled = true;
            }
        }

        if (dialogueActive)
        {
            if (NPCActive)
            {
                if (currentNPC.hasOptions && currentNPC.optionsVisible)
                {
                    optionsBox.SetActive(true);
                    int     coefficient = currentNPC.options.Count;
                    Vector3 selectorPos = optionSelector.transform.position;
                    if (Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        selectedOption = (selectedOption + coefficient - 1) % coefficient;
                    }
                    if (Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        selectedOption = (selectedOption + 1) % coefficient;
                    }
                    if (currentNPC.NPCName != "수상한 초상화" && currentNPC.NPCName != "횃불")
                    {
                        selectorPos.y = optionsParent.transform.GetChild(selectedOption).transform.position.y;
                    }

                    if (Input.GetKeyDown(KeyCode.LeftControl))
                    {
                        string temp = currentNPC.selectOption(selectedOption);
                        if (!endingTriggered)
                        {
                            GameObject.Find("infoA").GetComponent <Text>().text = temp;                                          // code in individual Objects
                        }
                        infoB.SetActive(false);
                        optionsBox.SetActive(false);
                        selectorPos.y             = optionsParent.transform.position.y;
                        currentNPC.optionsVisible = false;
                    }
                    optionSelector.transform.position = selectorPos;
                }
                else
                {
                    optionsBox.SetActive(false);
                    if (Input.GetKeyDown(KeyCode.LeftControl))
                    {
                        dialogueActive = false;
                        dialogueCanvas.gameObject.SetActive(false);
                        currentNPC.active = false;
                    }
                }
            }
            else
            {
                // Key bindings for dialogue UI
                if (currentObj.hasOptions && currentObj.optionsVisible)
                {
                    optionsBox.SetActive(true);
                    Vector3 selectorPos = optionSelector.transform.position;
                    int     coefficient = currentObj.options.Length;
                    if (Input.GetKeyDown(KeyCode.UpArrow))
                    {
                        selectedOption = (selectedOption + coefficient - 1) % coefficient;
                    }
                    if (Input.GetKeyDown(KeyCode.DownArrow))
                    {
                        selectedOption = (selectedOption + 1) % coefficient;
                    }
                    selectorPos.y = optionsParent.transform.GetChild(selectedOption).transform.position.y;
                    if (Input.GetKeyDown(KeyCode.LeftControl))
                    {
                        GameObject.Find("infoA").GetComponent <Text>().text = currentObj.selectOption(selectedOption);
                        infoB.SetActive(false);
                        selectorPos.y = optionsParent.transform.position.y;
                        optionsBox.SetActive(false);
                        currentObj.optionsVisible = false;
                    }
                    optionSelector.transform.position = selectorPos;
                }
                else
                {
                    optionsBox.SetActive(false);
                    if (Input.GetKeyDown(KeyCode.LeftControl))
                    {
                        dialogueActive = false;
                        dialogueCanvas.gameObject.SetActive(false);
                        currentObj.active = false;
                    }
                }

                if (Input.GetKeyDown(KeyCode.Z))
                {
                    inventory.addItem(currentObj);
                    Destroy(currentObj.gameObject);
                }
            }
        }
        else
        {
            dialogueCanvas.gameObject.SetActive(false);
        }


        if (doorActive)
        {
            Vector3 selectorPos = doorSelector.transform.position;
            int     coefficient = currentDoor.goalPosition.Length;

            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                selectedDoor = (selectedDoor + coefficient - 1) % coefficient;
            }
            if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                selectedDoor = (selectedDoor + 1) % coefficient;
            }
            selectorPos.y = doorParent.transform.GetChild(selectedDoor).transform.position.y;

            if (Input.GetKeyDown(KeyCode.LeftControl))
            {
                teleported = true;
                this.transform.position = currentDoor.getDestination(currentDoor.goalPosition[selectedDoor]);
                doorText.text           = currentDoor.goalPosition[selectedDoor].positionName;
                selectorPos.y           = doorParent.transform.position.y;
            }
            doorSelector.transform.position = selectorPos;
        }
    }