Example #1
0
    private void Update()
    {
        /*
         * If conversation is activated from collider, further code will execute.
         *
         * Player is called to be set Freezed.
         * Background sprite is activated.
         *
         * Then line is printed by letter, with small delay that creates writing effect.
         * If you want to speed up the writing, you can press space.
         *
         * If text is printed out and you press space:
         *          - If there´s still lines, is next line converted to letters and will be printed next.
         *          - If there´s no lines left, the code resets and code destroys itself.
         *
         */

        if (active)
        {
            player.SetFreeze(true);
            background.SetActive(true);

            timer -= 0.1f;
            if (timer <= 0 && index < letters.Length)
            {
                timer         += 1f;
                tempLine      += letters[index];
                textKupla.text = tempLine;
                index         += 1;
            }
            else if (Input.GetKeyDown(key[lineRound]) && index >= letters.Length)
            {
                lineRound += 1;

                if (lineRound < line.Length)
                {
                    index          = 0;
                    textKupla.text = "";
                    tempLine       = null;
                    letters        = null;
                    letters        = line[lineRound].ToCharArray();
                    timer         += 1f;
                }
                else if (lineRound >= line.Length)
                {
                    textKupla.text = "";
                    player.SetFreeze(false);
                    background.SetActive(false);
                    Destroy(gameObject);
                }
            }
            else if (Input.GetKey("space") && index < letters.Length)
            {
                timer = -1;
            }
        }
    }
Example #2
0
    private void Update()
    {
        /* If conversation is activated from collider, further code will execute.
         *
         * Player is called to be set Freezed.
         * Name is printed to view and background sprite is activated.
         * Speaker sprite is also activated.
         *
         * Then line is printed by letter, with small delay that creates writing effect.
         * If you want to speed up the writing, you can press space.
         * If text is printed out and you press space:
         *          - If there´s still lines, is next line converted to letters and new sprite and name will be refreshed.
         *          - If there´s no lines left, the code checks if conversation has been set repeatable or not.
         *                  - If it´s set repeatable, will code be destroyed in the end.
         *                  - Otherwise code will be only reseted and you can go trough same conversation as many times as you like.
         *
         */

        if (active)
        {
            player.SetFreeze(true);
            nimiKupla.text = nimi[lineRound];
            background.SetActive(true);
            sprites[lineRound].SetActive(true);

            timer -= 0.1f;
            if (timer <= 0 && index < letters.Length)
            {
                timer         += 1f;
                tempLine      += letters[index];
                textKupla.text = tempLine;
                index         += 1;
            }
            else if (Input.GetKeyDown("space") && index >= letters.Length)
            {
                lineRound += 1;

                textKupla.text = "";
                nimiKupla.text = "";

                if (lineRound < line.Length)
                {
                    sprites[lineRound - 1].SetActive(false);
                    index    = 0;
                    tempLine = null;
                    letters  = null;
                    letters  = line[lineRound].ToCharArray();
                    timer   += 1f;
                }
                else if (lineRound >= line.Length)
                {
                    player.SetFreeze(false);
                    background.SetActive(false);
                    resetSprites();
                    active = false;

                    if (repeatable)
                    {
                        index     = 0;
                        lineRound = 0;
                        tempLine  = null;
                        letters   = null;
                        letters   = line[lineRound].ToCharArray();
                    }
                    else
                    {
                        Destroy(this);
                    }
                }
            }
        }
    }