- Home /
Question by
nicolereginechang · Nov 11, 2019 at 03:00 PM ·
c#drag-and-dropcheckspellchecking
Help! How to check letter spelling automatically after drag and drop
Hi! Been trying to figure out for awhile but couldn't think of a way how to automatically check letters whether spelling is correct one by one when each letter is drag and dropped into the column (kids spelling game) ? Im making a very small game just to try out. For example if the word is banana, when you drag letter b then letter c into the column, it will delete both letters and show a feedback saying its wrong.
I already have a drag and drop script. This is what I currently have for the checking answers script but it's not what i want because it uses a RMB to check the word and only when you have the full word out.
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class GMScript : MonoBehaviour {
public static string currentWord;
public Transform spelledWord;
public Transform letter1;
public Transform letter2;
public Transform letter3;
public Transform letter4;
public Transform letter5;
public Transform letter6;
public Transform letter7;
public Transform letter8;
public Transform letter9;
public Transform letter10;
public Transform letter11;
public Transform letter12;
public KeyCode RMB; //the button clicked to check spelling (what if wan auto check every letter everytime)
public int wordLength;
public string apple = "APPLE";
public string banana = "BANANA";
public string blueberry = "BLUEBERRY";
public static List<string> selectLetter = new List<string>() {"","","","","","","","",""};
public static int letterNum = 0;
public GameObject appleprizesoil1;
public GameObject bananaprizesoil1;
public GameObject blueberryprizesoil1;
// Use this for initialization
void Start () {
appleprizesoil1.SetActive(false);
}
// Update is called once per frame
void Update () {
spelledWord.GetComponent<TextMesh> ().text = currentWord;
if (Input.GetKeyDown (RMB))
{
wordLength = currentWord.Length;
}
if (wordLength == 5){
if (currentWord == apple) {
Debug.Log("Correct spelling of apple");
letter1.GetComponent<TextMesh> ().text = selectLetter [1];
letter1.GetComponent<TextMesh> ().text = selectLetter [2];
letter1.GetComponent<TextMesh> ().text = selectLetter [3];
letter1.GetComponent<TextMesh> ().text = selectLetter [4];
letter1.GetComponent<TextMesh> ().text = selectLetter [5];
appleprizesoil1.SetActive(true);
}
else {
Debug.Log ("Wrong spelling of apple");
}
}
if (wordLength == 6){
if (currentWord == banana) {
Debug.Log("Correct spelling of banana");
letter1.GetComponent<TextMesh> ().text = selectLetter [1];
letter1.GetComponent<TextMesh> ().text = selectLetter [2];
letter1.GetComponent<TextMesh> ().text = selectLetter [3];
letter1.GetComponent<TextMesh> ().text = selectLetter [4];
letter1.GetComponent<TextMesh> ().text = selectLetter [5];
letter1.GetComponent<TextMesh> ().text = selectLetter [6];
}
else {
Debug.Log ("Wrong spelling of banana");
}
}
if (wordLength == 9){
if (currentWord == banana) {
Debug.Log("Correct spelling of blueberry");
letter1.GetComponent<TextMesh> ().text = selectLetter [1];
letter1.GetComponent<TextMesh> ().text = selectLetter [2];
letter1.GetComponent<TextMesh> ().text = selectLetter [3];
letter1.GetComponent<TextMesh> ().text = selectLetter [4];
letter1.GetComponent<TextMesh> ().text = selectLetter [5];
letter1.GetComponent<TextMesh> ().text = selectLetter [6];
letter1.GetComponent<TextMesh> ().text = selectLetter [7];
letter1.GetComponent<TextMesh> ().text = selectLetter [8];
letter1.GetComponent<TextMesh> ().text = selectLetter [9];
}
else {
Debug.Log ("Wrong spelling of blueberry");
}
}
}
}
Comment