Пример #1
0
    // Update is called once per frame
    void Update()
    {
        if (started && pauseStartTime + 1f > 0.0001f)
        {
            if (Time.time - startTime > randomInputDelay)
            {
                startTime = Time.time;
                if (currentState.randomInputPercent > Random.value)
                {
                    RandomInput();
                }
            }

            bool left   = Input.GetButtonDown("Left");
            bool right  = Input.GetButtonDown("Right");
            bool up     = Input.GetButtonDown("Up");
            bool down   = Input.GetButtonDown("Down");
            bool a      = Input.GetButtonDown("A");
            bool b      = Input.GetButtonDown("B");
            bool escape = Input.GetButton("Escape");
            if (left || right || up || down || a || b || escape)
            {
                float decisionValue = Random.value;
                if (decisionValue < currentState.listenPercent)
                {
                    if (right)
                    {
                        currentGame.Right();
                    }
                    if (left)
                    {
                        currentGame.Left();
                    }
                    if (up)
                    {
                        currentGame.Up();
                    }
                    if (down)
                    {
                        currentGame.Down();
                    }
                    if (a)
                    {
                        currentGame.A();
                    }
                    if (b)
                    {
                        currentGame.B();
                    }
                    if (escape)
                    {
                        StopGame();
                        ExitGame();
                    }
                }
                else if (1 - decisionValue < currentState.wrongInputPercent)
                {
                    RandomInput();
                }
                else
                {
                    AudioSource audio = GetComponent <AudioSource>();
                    audio.clip = IgnoredSound;
                    audio.Play();
                    Debug.Log("not listening");
                }
            }
            if (Time.time - pauseStartTime >= pauseInterval && pauseStartTime != -1f)
            {
                List <int> options = currentGame.GetPossibleDialogueNodes();
                pauseStartTime = Time.time;
                if (options == null || options.Count > 0)
                {
                    pauseStartTime = -1f;
                    currentGame.Pause();
                    Dialogue dialogue  = GameObject.FindGameObjectWithTag("Dialogue").GetComponent <Dialogue>();
                    int      optionNum = Random.Range(0, options.Count);
                    if (options[optionNum] == 12)
                    {
                        GameObject gameChan = GameObject.FindGameObjectWithTag("ControllerChan");
                        Vector3    position = gameChan.transform.position;
                        position.x += 250f;
                        gameChan.transform.position = position;
                    }
                    Debug.Log("Chose option " + options[optionNum]);
                    dialogue.DialogueInit(options[optionNum]);
                }
            }
        }
    }