User String Input

In c# how would you do this?

This is in java.

import.java.util

//variables 

String inputUser = "";
String word1 = "apple";



Scanner keyboard = new Scanner(System.in) 

System.out.println("Enter The Word"); 
inputUser = keyboard.nextLine();  

if(inputUser.equals(word1)) 
{

  System.out.println("Yay you got it right!");
}
Else 
{ 
System.out.Println("Not correct!");

I know debug.log is System.out.println. I’m just looking how to get user input with full strings. Thank you.

In pure C# it looks like this:

string word1 = "apple";

string inputUser = Console.ReadLine();
if(inputUser.Equals(word1))
	Console.WriteLine("Yay you got it right!");
else
	Console.WriteLine("Not correct!");

but it doesn’t connect with Unity, as and your code though.

How would you do this with unity? I’m trying to input a whole string .

Use the methods available in GUI or GUILayout to create an input field for the user or read Input.GetKeyDown inside Update to piece a string together when the user hits a key. There’s no concept of reading an input string out of the console in Unity.

You would need to use GUI controls and have a label saying “Enter The Word” then a textfield for the input but use a button to submit the input then call a function or whatever to compare the input string with word1 then display another label based on this comparison.

http://docs.unity3d.com/Documentation/Components/gui-Controls.html

is this at all possible without a GUI? I’m trying to do this exact same thing but straight to console

No. If you want to use System.Console then why are you using Unity in the first place?

1 Like

If you need it you can build an in game console. It’s pretty simple with the new UI tools.