modify this unity c# script so instead of talking senteces it extracts texts from pdf…
- User
modify this unity c# script so instead of talking senteces it extracts texts from pdf like this html. unity script: using UnityEngine; using TMPro; using UnityEngine.UI; using System.Linq; using System.Collections.Generic;
public class AIResponse_Realistic : MonoBehaviour { // Reference to the TMP_InputField, TMP_Text, and Button UI elements public TMP_InputField userInputField; public TMP_Text aiResponseText; public Button submitButton; // The Enter button
// Vocabulary categories with words and associated meanings (in code for understanding) private Dictionary<string, List<WordData>> vocabularyCategories = new Dictionary<string, List<WordData>>() { { "greetings", new List<WordData>{ new WordData("hello", "a greeting used to express happiness or acknowledge someone"), new WordData("hi", "informal greeting to acknowledge someone"), new WordData("hey", "casual greeting often used among friends"), new WordData("greetings", "a formal greeting or expression of goodwill"), new WordData("good morning", "a greeting used in the early part of the day"), new WordData("good evening", "a greeting used in the evening"), }}, { "emotions", new List<WordData>{ new WordData("happy", "feeling or showing pleasure or contentment"), new WordData("sad", "feeling sorrowful or downcast"), new WordData("excited", "feeling enthusiastic or eager about something"), new WordData("angry", "feeling strong displeasure or hostility"), new WordData("bored", "feeling weary and uninterested"), new WordData("joyful", "feeling or expressing happiness"), }}, { "questions", new List<WordData>{ new WordData("how", "in what way or manner; by what means"), new WordData("where", "in or to what place or position"), new WordData("why", "for what reason or purpose"), new WordData("what", "used to ask about something"), new WordData("when", "at what time or period"), }}, { "actions", new List<WordData>{ new WordData("eat", "to take in food through the mouth"), new WordData("run", "to move swiftly on foot"), new WordData("play", "to engage in activities for enjoyment or recreation"), new WordData("talk", "to communicate using spoken words"), new WordData("sleep", "to rest with eyes closed and mind inactive"), }}, { "statements", new List<WordData>{ new WordData("good", "having positive qualities or being satisfactory"), new WordData("bad", "having negative qualities or being unsatisfactory"), new WordData("fine", "of acceptable quality or condition"), new WordData("okay", "satisfactory but not exceptional"), new WordData("great", "being of excellent quality or large extent"), }}, }; // A list to hold all words from the vocabulary private List<WordData> allWords = new List<WordData>(); private void Start() { // Flatten all vocabulary categories into one list for easy access allWords = vocabularyCategories.Values.SelectMany(category => category).ToList(); // Add event listener to the submit button submitButton.onClick.AddListener(OnSubmit); // Add event listener for input changes (optional for dynamic responses) userInputField.onValueChanged.AddListener(OnInputChanged); } private void OnSubmit() { // Get the user input text string userInput = userInputField.text.ToLower(); // Find words in the user input that match the vocabulary list var matchedWords = allWords.Where(word => userInput.Contains(word.word)).ToList(); // If we find any matches, generate a response if (matchedWords.Count > 0) { // Generate a more natural-sounding response using random words string response = GenerateAIResponse(matchedWords); aiResponseText.text = response; } else { aiResponseText.text = "I didn’t quite understand that, could you say it in another way?"; } // Clear the input field userInputField.text = string.Empty; } // Generate a more natural-sounding response from the vocabulary words private string GenerateAIResponse(List<WordData> matchedWords) { string response = string.Empty; // Randomly pick words from the matched list and use them in a sentence // For example, if the word is "happy", the AI might respond with "I hope you're feeling happy today!" foreach (var wordData in matchedWords) { switch (wordData.word) { case "hello": response += "Hi! "; break; case "how": response += "How are you? "; break; case "happy": response += "I hope you're feeling happy today! "; break; case "sad": response += "It seems like something might be bothering you. "; break; case "excited": response += "It sounds like you're really excited! "; break; case "good": response += "That's good to hear! "; break; case "bad": response += "That sounds bad. What happened? "; break; case "run": response += "Are you planning to go for a run? "; break; case "sleep": response += "You should get some rest if you're tired. "; break; case "play": response += "What would you like to play today? "; break; default: response += "Hmm, I’m not sure how to respond to that. "; break; } } // If no response has been generated yet, return a default message if (string.IsNullOrEmpty(response)) { response = "Hmm, I'm not sure what you're trying to say. Can you explain more?"; } return response; } // Optional: Respond dynamically as the user types (for immediate feedback) private void OnInputChanged(string input) { // Can add real-time responses based on user input } - Assistant