Esempio n. 1
0
    public IEnumerator DialogCoroutine()
    {
        prompt.SetActive(true);
        prompt.GetComponent <TextMeshPro>().text = "!";
        GameObject player = GameObject.FindGameObjectsWithTag("Player")[0];

        // Do beginning dialog
        if (beginDialog != null)
        {
            int index = 0;

            yield return(new WaitForSeconds(1.0f));

            prompt.GetComponent <TextMeshPro>().text = "[SPACE]";
            dialogText.SetActive(true);
            while (index < beginDialog.speech.Length)
            {
                Vector3 newPos = dialogText.transform.position;
                if ((target == null) || ((index % 2 == 0) == beginDialog.playerBegins))
                {
                    newPos.x = GameObject.FindGameObjectsWithTag("Player")[0].transform.position.x;
                }
                else
                {
                    newPos.x = target.transform.position.x;
                }
                dialogText.transform.position = newPos;

                dialogText.GetComponent <TextMeshPro>().text = beginDialog.speech[index];
                while (!Input.GetButtonDown("Jump"))
                {
                    yield return(null);
                }
                index++;
                yield return(null);
            }
        }

        // Do choice
        if (target != null)
        {
            killText.SetActive(true);
            danceText.SetActive(true);
            arrow.gameObject.SetActive(true);

            waitingForChoice = true;

            bool choseKill = false;
            while (waitingForChoice)
            {
                float phase = Mathf.Sin(Mathf.PI * Time.time);
                arrow.localScale               = new Vector3(Mathf.Sign(phase) * (Mathf.Abs(phase / 2) + 0.5f), Mathf.Abs(phase / 2) + 0.5f, 1);
                arrow.transform.rotation       = Quaternion.Euler(0, 0, Mathf.Sin(Mathf.PI * Time.time + Mathf.PI / 3) * -7.0f);
                killText.transform.localScale  = Mathf.Lerp(0.5f, 1, (phase + 1) / 2) * Vector3.one;
                killText.transform.rotation    = Quaternion.Euler(0, 0, Mathf.Sin(Mathf.PI * Time.time + 2 * Mathf.PI / 3) * 7.0f);
                danceText.transform.localScale = Mathf.Lerp(0.5f, 1, (-phase + 1) / 2) * Vector3.one;
                danceText.transform.rotation   = Quaternion.Euler(0, 0, phase * 7.0f);
                if (Input.GetButtonDown("Jump"))
                {
                    Debug.Log(phase > 0 ? "Kill" : "Join");
                    arrow.GetComponent <SpriteRenderer>().color = selectionColor;
                    if (phase > 0)
                    {
                        killText.GetComponent <TextMeshPro>().faceColor = selectionColor;
                        choseKill = true;
                    }
                    else
                    {
                        danceText.GetComponent <TextMeshPro>().faceColor = selectionColor;
                    }
                    waitingForChoice = false;
                }
                yield return(null);
            }
            yield return(new WaitForSeconds(1.0f));

            killText.SetActive(false);
            danceText.SetActive(false);
            arrow.gameObject.SetActive(false);

            // Do end dialog
            DialogData choiceDialog = choseKill ? killDialog : hugDialog;
            if (choiceDialog != null)
            {
                int index = 0;
                dialogText.SetActive(true);
                while (index < choiceDialog.speech.Length)
                {
                    Vector3 newPos = dialogText.transform.position;
                    if ((target == null) || ((index % 2 == 0) == choiceDialog.playerBegins))
                    {
                        newPos.x = GameObject.FindGameObjectsWithTag("Player")[0].transform.position.x;
                    }
                    else
                    {
                        newPos.x = target.transform.position.x;
                    }
                    dialogText.transform.position = newPos;

                    dialogText.GetComponent <TextMeshPro>().text = choiceDialog.speech[index];
                    while (!Input.GetButtonDown("Jump"))
                    {
                        yield return(null);
                    }
                    index++;
                    yield return(null);
                }
            }
            prompt.SetActive(false);
            dialogText.SetActive(false);

            if (choseKill)
            {
                target.SetMovementEnabled(true);
                player.GetComponent <PlayerController>().enabled = true;
                gameObject.SetActive(false);
            }
            else
            {
                foreach (Collider2D c in target.GetComponentsInChildren <Collider2D>())
                {
                    c.enabled = false;
                }
                target.GetComponentInChildren <Rigidbody2D>().isKinematic = true;
                StartCoroutine(MoveToCoroutine());
            }
        }
        else
        {
            player.GetComponent <PlayerController>().enabled = true;
            gameObject.SetActive(false);
        }
    }