Пример #1
0
    void UpdateResponse()
    {
        string response = "";

        // positive feedback
        if (Score.Value > lastScore)
        {
            if (goodResponses.Count > 0)
            {
                response = goodResponses[UnityEngine.Random.Range(0, goodResponses.Count)];
            }
        }

        // negative feedback
        else if (Score.Value < lastScore)
        {
            if (badResponses.Count > 0)
            {
                response = badResponses[UnityEngine.Random.Range(0, badResponses.Count)];
            }
        }

        // neutral feedback
        else
        {
            if (neutralResponses.Count > 0)
            {
                response = neutralResponses[UnityEngine.Random.Range(0, neutralResponses.Count)];
            }
        }

        // BubbleTalk.text = response;
        Talk.CreateTalk(response, TalkObject.Side.Right);

        lastScore = Score.Value;

        UpdateConditions();
    }
Пример #2
0
    // callback when player clicks "Send"
    // handles player input
    public void OnSubmit()
    {
        // get player input as a string
        string input = TextInputField.text;

        if (input.Equals(""))
        {
            return;
        }
        Debug.Log("on submit: " + input);

        // update conversation
        Talk.CreateTalk(input, TalkObject.Side.Left);

        // clear player input field
        TextInputField.text = "";

        // regx match to bad word list - each bad word -1
        int numBadWords = 0;

        foreach (string word in badWords)
        {
            MatchCollection matches = Regex.Matches(input, @"\b" + word + @"\b");
            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    Debug.Log("Found bad word: " + word);
                }
            }
            numBadWords += matches.Count;
        }
        Debug.Log("bad words # = " + numBadWords);

        // regx match to goos word list - each good word +1
        int numGoodWords = 0;

        foreach (string word in goodWords)
        {
            MatchCollection matches = Regex.Matches(input, @"\b" + word + @"\b");
            if (matches.Count > 0)
            {
                foreach (Match match in matches)
                {
                    Debug.Log("Found good word: " + word);
                }
            }
            numGoodWords += matches.Count;
        }
        Debug.Log("good words # = " + numGoodWords);

        // update score
        int scoreDiff = numBadWords * ADD_BAD + numGoodWords * ADD_GOOD;

        Score.Value = Score.Value + scoreDiff;

        // activate input
        TextInputField.ActivateInputField();

        CheckScore();
    }