- Home /
Need help with typing game
I think this is the first game im making where i dont know how to start, so im asking. I do know how to script and i have been using unity for two years. But this project bugs me. I wanna make a typing game where a text appears and you need to type what it says. For example the box says "This is your first lesson" Then you need to type the sentence. When i type the first letter T the t in the box needs to become green, and so on when i type the next letter. If i press the wrong key, the letter becomes red. Hope someone can help!
Answer by Derpybunneh · Sep 03, 2016 at 08:56 PM
(This makes sense in my head, but it might not actually work...)
I can't provide any legit code for you, but I can try my best to help you think it out.
First you probably want to store the text you want the player to type in a text UI object in a typing script or something. Then in that typing script you should get the number of characters in your line of text and store it in an integer. Then you'd probably want to create an int called characterBeingTyped that will keep track of the current int your on of the overall characters in your line of text. For example, if I have a text 5 letters long, and I'm supposed to type the first letter, then characterBeingTyped would be 0. Next, you should store each character of your word in a characters array.
Next, you'd probably want a for or while loop that will loop through the characters you want to type as long as they are less than the number of characters in the text int.
(This code will not actually work, it's just some pseudo code) `
for (characterToType = 0; characterToType < textCharacters; characterToType++) {
if (Input.anyKeyDown) {
// Get key that was pressed down
if (keyThatWasPressedDown == characters[characterToType]) {
// Make character green... somehow
} else {
// Make character red... somehow
}
}
}
Sorry I can't do much to help answer your question! But that might be able to get you started with the general idea.
Your answer
Follow this Question
Related Questions
Determine if game object is tyoepf One Prefab 3 Answers
How to get the type of a Gameobject 3 Answers
using Contains(gameObject) to find and destroy a gameObject from a list 2 Answers
What is the type of my prefab? 2 Answers
UI button keyboard input into typing game ,UI button keyboard to input to Typing Game 1 Answer