So I have a script that lets the user type a string and hit enter, only to have the machine reply. However, I want to make it so that if the user asks for a certain day, color, etc in the string, it will pull it from a list?
Let's say you want to ask the machine which day of the week is it's favorite. Instead of typing out every possible day like this:
//User Input
var stringToEdit : String = " ";
private var aiResponse : String = " ";
function OnGUI () {
stringToEdit = GUI.TextField (Rect (320, 145, 200, 20), stringToEdit, 25);
GUI.Box(Rect(0,0,Screen.width,Screen.height), aiResponse);
}
function Update() {
if(Input.GetKeyDown (KeyCode.Return))
{
if(stringToEdit.ToLower() == "Do you like Tuesdays?" || "Do you like Wednesdays?")
{
aiResponse = days[Random.Range(1,days.length)];
stringToEdit = "";
}
}
}
Could I maybe do something like this? Where it accesses a list of days and checks in the string if the day is on the list?
//User Input
var stringToEdit : String = " ";
private var aiResponse : String = " ";
function OnGUI () {
stringToEdit = GUI.TextField (Rect (320, 145, 200, 20), stringToEdit, 25);
GUI.Box(Rect(0,0,Screen.width,Screen.height), aiResponse);
}
var listOfDays : List or something;
function Update() {
if(Input.GetKeyDown (KeyCode.Return))
{
if(stringToEdit.ToLower() == "Do you like" dayOfTheWeek "?")
{
aiResponse = days[Random.Range(1,days.length)];
stringToEdit = "";
}
}
}
Any advice? I have no idea how to set this up. Thanks.
↧