Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by grant · Apr 18, 2011 at 01:19 AM · type

Typing Game script

Hi I am trying to make a typing game that is based on comparing strings and this is the script for the first word "The". Everything works except that when I use Event.Current.isKey and display it on my string it wont let me use the backspace to delete the letter already typed. Please Help.

var theString : String = ""; var theSkin : GUISkin; var The : GameObject;

function OnGUI() {

GUI.skin = theSkin;

GUI.TextField(Rect(100, 200, 200, 20), theString, 3); Word1(); }

static var lastChar : String = "";

function Word1() { if (Event.current.isKey) { if (lastChar != Event.current.character) { lastChar = Event.current.character.ToString();

         switch (lastChar) {
             case ("a"): theString += "a"; break;
             case ("b"): theString += "b"; break;
             case ("c"): theString += "c"; break;
             case ("d"): theString += "d"; break;
             case ("e"): theString += "e"; break;
             case ("f"): theString += "f"; break;
             case ("g"): theString += "g"; break;
             case ("h"): theString += "h"; break;
             case ("i"): theString += "i"; break;
             case ("j"): theString += "j"; break;
             case ("k"): theString += "k"; break;
             case ("l"): theString += "l"; break;
             case ("m"): theString += "m"; break;
             case ("n"): theString += "n"; break;
             case ("o"): theString += "o"; break;
             case ("p"): theString += "p"; break;
             case ("q"): theString += "q"; break;
             case ("r"): theString += "r"; break;
             case ("s"): theString += "s"; break;
             case ("t"): theString += "t"; break;
             case ("u"): theString += "u"; break;
             case ("v"): theString += "v"; break;
             case ("w"): theString += "w"; break;
             case ("x"): theString += "x"; break;
             case ("y"): theString += "y"; break;
             case ("z"): theString += "z"; break;
             case ("A"): theString += "A"; break;
             case ("B"): theString += "B"; break;
             case ("C"): theString += "C"; break;
             case ("D"): theString += "D"; break;
             case ("E"): theString += "E"; break;
             case ("F"): theString += "F"; break;
             case ("G"): theString += "G"; break;
             case ("H"): theString += "H"; break;
             case ("I"): theString += "I"; break;
             case ("J"): theString += "J"; break;
             case ("K"): theString += "K"; break;
             case ("L"): theString += "L"; break;
             case ("M"): theString += "M"; break;
             case ("N"): theString += "N"; break;
             case ("O"): theString += "O"; break;
             case ("P"): theString += "P"; break;
             case ("Q"): theString += "Q"; break;
             case ("R"): theString += "R"; break;
             case ("S"): theString += "S"; break;
             case ("T"): theString += "T"; break;
             case ("U"): theString += "U"; break;
             case ("V"): theString += "V"; break;
             case ("W"): theString += "W"; break;
             case ("X"): theString += "X"; break;
             case ("Y"): theString += "Y"; break;
             case ("Z"): theString += "Z"; break;

             default: break;
         }

         var compString : String = "The";
         var compString2 : String = "a";

         if (theString == compString) {
             The.GetComponent("TheGreen").enabled = true;
             }

         if (theString == compString2) {
             The.GetComponent("TheRed").enabled = true;
         }

         if (Input.GetKeyDown("backspace")){
                        // this is where I would like to delete one character at a time but dont know what script to use      


          The.GetComponent("TheClear").enabled = true;
         }

     }
 }

}

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by Jesse Anders · Apr 18, 2011 at 01:31 AM

It looks like the formatting in your post got messed up. Try editing your post and reposting the code (making sure that all the code is correctly formatted).

You said using backspace to remove characters isn't working, but it doesn't look like you've actually implemented any code for that. Can you clarify what the problem is?

Oh, and I'm sure you don't need that big switch statement ;) I'm not sure what you're trying to do exactly, but I'm sure there's a more direct way to accomplish whatever it is you're trying to accomplish.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image grant · Apr 18, 2011 at 01:45 AM 0
Share

There, fixed the formatting. And your definitely right that I dont need that big switch statement. I just didnt exactly know how to go about this. I am trying to make an educational game for a competition that $$anonymous$$ches kids typing and what I am trying to do is have a sentence above a GUI TextField that you have to type and match the words and for every word you type correctly I wanted to turn the word green showing that you typed it correctly. That part works but however when you make a mistake typing it and you hit the backspace button it wont delete the characters already typed.

avatar image Jesse Anders · Apr 18, 2011 at 07:46 AM 0
Share

Wait, are you asking how to delete a character, or are you just saying that your current method isn't working? (Because you said it 'won't let you' delete a character, my assumption was that you have some code in place for this already, but that it's not working as you expect.)

avatar image
0

Answer by Joshua · Apr 18, 2011 at 05:02 PM

Make use of this

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by hameed-ullah-jan · Feb 05, 2016 at 04:43 PM

Blockquote

Here is very simple solution to your answer, you just need to make "Text" in canvas and attach this simple script. download the attached script, it is in text format you just need to paste it int a c# script, make a script with name "Typing.cs" and past the code from the text file. hope your problem will be solved with this. [link text][1] using UnityEngine; using System.Collections; using UnityEngine.UI; // written by hameed ullah jan public class Typing : MonoBehaviour { private float letterpause = 0.1f; public AudioClip sound; // typing sound private string mytext; // Use this for initialization void Start () { mytext = "CHASE YOUR FIRST PASSENGER PLANE AND FUEL IT BEFORE IT FALLS"; StartCoroutine ( TypeText ()); }
// Update is called once per frame void Update () {
} IEnumerator TypeText (){ Debug.Log ("called"); foreach(char letter in mytext.ToCharArray()){ this.GetComponent().text += letter; if(sound) { if(!GetComponent().isPlaying){ GetComponent().PlayOneShot(sound); } yield return new WaitForSeconds(letterpause); } } } } > Blockquote [1]: /storage/temp/63300-typing.txt

typing.txt (829 B)
Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

1 Person is following this question.

avatar image

Related Questions

Boo help: method not defined 4 Answers

enable / disable a script without dynamic typing 2 Answers

"Type" type 1 Answer

How to set animations to loop? 1 Answer

Easy? Convert System.Type to UnityEngine.Component 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges