String comparision

I have a string “Hello World” which is displayed as white color in the game view.
Now if I press e, e in Hello World should be highlighted i.e. e will become black.

Firs of all how to check which key i have pressed. Second I have to check if e is pressed then change e color in Hello World.
I am using this script.

	private string displayedStr, correctStr;
	
	public GUIStyle stringStyle, stringStyle1;

	void Start () 
	{
		displayedStr = "Hello World";
		correctStr = "";
	}
	
	void Update () 
	{
		if(Input.anyKeyDown)
		{
			Debug.Log(Input.inputString);
			
			for(int i=0; i<displayedStr.Length; i++)
			{
				if(Input.inputString.Contains(displayedStr*.ToString()))*
  •  		{*
    
  •  			Debug.Log("Correct");*
    
  •  		}*
    
  •  		else*
    
  •  		{*
    
  •  			Debug.Log("Wrong");*
    
  •  		}*
    
  •  	}*
    
  •  }* 
    
  • }*

  • void OnGUI()*

  • {*

  •  GUI.Label(new Rect(300, 100, 100, 100), displayedStr, stringStyle);*
    
  •  GUI.Label(new Rect(300, 100, 100, 100), correctStr, stringStyle1);*
    
  • }*
    I know I am doing lot of things wrong here. For correctStr I should check if that letter exists then only display that letter, something like that.

// The first thing you do is check the character is in the string like you’ve done already, but in a different approach

correctStr = Input.inputString;

// assign the latest input into this string

for (int i = 0; i < displayedStr.Length; i++)
{
    if (displayedStr *== correctStr)*

{
Debug.Log(“Correct.”);
}
}
This could possibly help, but it needs testing.

try this:

if (displayedStr*.ToString() == correctStr)*

{
// etc etc
}
EDIT: You probably also want to make sure that correctStr wont get larger than 1 character at a time so in your update function you should check that if it is larger than 1 char, resize the string to 1 char.

Really??? The documentation is pretty good:

The two examples there show how to check if the space key is down. If you need help figuring out when the e key is pressed, see:

Next, to change the colour, check out:

http://docs.unity3d.com/Documentation/Manual/StyledText.html

This tells you how you can change colours of text. The complication you have is that this does not work directly with GUI.Label. You need to use a GUIStyle, so see:

to learn about that.