- Home /
Need help in typing project
Hi, Am doing a typing game project , its for kids, in a google search i find one reference code its exactly match what i want, then i modify the code what i want it to.
Here the problem is , in a word "APPLE" the "P" letter is twice so my the code finds multiple "P" letter at a time, i want it to find or check one letter and in a sequence, please give me some help in this to achieve this.
Below is the Code C#
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 using UnityEngine.UI;
  
 public class LetterButton : MonoBehaviour
 {
     public Button[] aLetter;
     private GameObject centre;
     public RectTransform gameCharContainer;
     public GameObject alphabetLetter;
  
     private string wordToType = "";
     private int lengthOfWordToType;
     char [] lettersToType;
     public bool [] lettersTyped;
  
     private string [] wordsToType = new string [] {"apple", "ball","cat","dog","elephant"};
  
     void Start ()
     {
         centre = GameObject.Find ("Centre Text GO");
  
  
         initGame ();
  
         GamePlayFunction ();
  
         IntLettersPressed ();
     }
  
     void initGame()
     {
  
         int numberOfWords = Random.Range(0,wordsToType.Length-1);
  
         wordToType = wordsToType [numberOfWords];
  
         lengthOfWordToType = wordToType.Length;
  
         wordToType = wordToType.ToUpper ();
  
         lettersToType = new char[lengthOfWordToType];
  
         lettersTyped = new bool [lengthOfWordToType];
  
         lettersToType = wordToType.ToCharArray ();
  
     }
  
     void GamePlayFunction()
     {
         int nbletters = lengthOfWordToType;
  
         for (int i = 0; i < nbletters; i++) {
             Vector3 newPosition;
             newPosition = new Vector3 (centre.transform.position.x + ((i-nbletters/2.0f) *70), centre.transform.position.y, centre.transform.position.z);
             GameObject l = (GameObject)Instantiate (alphabetLetter, newPosition, Quaternion.identity);
             l.name = "letter" + (i + 1);
             l.GetComponent<Text> ().text += wordToType[i];
             l.transform.SetParent (gameCharContainer, false);
         }
     }
  
     void IntLettersPressed()
     {
         for (int i = 0; i < aLetter.Length; i++) {
             Text a = aLetter[i].transform.FindChild("Text").GetComponent<Text>();
             aLetter[i].GetComponent<Button> ().onClick.AddListener (() => PressedBtn (a.text));
         }
     }
  
     void PressedBtn(string pressedLetter)//BY PRESSING THE GAME KEYBOARD BUTTONS
     {
         char letterTyped = pressedLetter.ToCharArray () [0];
         for (int i = 0; i < lengthOfWordToType; i++)
         {
             if (!lettersTyped [i])
             {
                 letterTyped = System.Char.ToUpper (letterTyped);
                 if (lettersToType [i] == letterTyped)
                 {
                     lettersTyped [i] = true;
                     GameObject.Find ("letter" + (i+1)).GetComponent<Text> ().color = new Color (0, 0, 0);
                 }
             }
  
         }
     }
 }
               Comment
              
 
               
              $$anonymous$$ore information please can you tell us exactly what you are trying to do.
Your answer
 
 
             Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Moving from Java to Unity 4 Answers
Is it possible to give a color to int variables? 1 Answer
Catch Game like Kaboom from Atari - Help Please! 0 Answers
Long string for dialog text 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                