-
Book Overview & Buying
-
Table Of Contents
-
Feedback & Rating
OUYA Game Development by Example
By :
Perform the following steps to add keyboard interaction to your scripts:
Add the following if statement to your Update function that checks if the Return key is pressed:
// Update is called once per frame
void Update()
{
if(Input.GetKeyDown(KeyCode.Return))
{
}
}Everything contained within the if statement will run every time the Update function detects that the Return key has just been pressed down (there's a slightly different way to check if a key is being held down, but we'll cover that in the next chapter).
We could add code directly inside the if statement to change the color of the text, but it's better to write a function for an action like that in case you want to replicate the same functionality outside of that if statement without writing redundant code, so we'll create a dedicated ChangeColor function.
Declare the ChangeColor function below the Update function in your ColorChanger script, as shown in the following code...
Change the font size
Change margin width
Change background colour