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 sharvari30 · Jul 08, 2013 at 08:46 PM · arraystringtap

Simple letters game

Letters appear on the screen one by one, at a rate of one per second.

Instructions: “Letter will appear on the screen one at a time. Every time you see the letter 'A', click the letter with your mouse. When letters other than 'A' appear, do NOT do click or tap the letter”.

Scoring: Give one point if there is an error (an error is a click on a wrong letter or a failure to click on letter A).

I am completely new to Unity. Can someone help me as to how should I start building this?

Thanks.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by aldonaletto · Jul 09, 2013 at 03:50 AM

TextMesh is a component, thus it only exists as part of a GameObject. When you create a 3D text with the Hierarchy Create button, a game object is created with a TextMesh component included.

In your case, a Raycast seems to be the more indicated: attach the script to the camera and verify what's being clicked. The code could be something like this:

 var score = 0; // the score increases each time an A is clicked
 
 function Update(){
   if (Input.GetMouseButtonDown(0)){ // if left button pressed...
     // calculate a ray passing through the mouse pointer:
     var ray = camera.ScreenPointToRay(Input.mousePosition);
     var hit: RaycastHit;
     if (Physics.Raycast(ray, hit)){ // if something hit...
       var txtMsh: TextMesh = hit.transform.GetComponent(TextMesh);
       // and if it's a TextMesh "A"...
       if (txtMsh && txtMsh.text == "A"){
           score++; // increment the score
       }
     }
   }
 }
     

You must add a box collider to the 3D text object - due to some weird reason, mesh colliders in 3D text objects aren't detected by Raycast.

Notice that the logic above seems opposed to what your question says: the score is incremented when an A is clicked. If you want to increase the score when an error occurs, change the logic:

     ...
     if (Physics.Raycast(ray, hit)){ // if something hit...
       var txtMsh: TextMesh = hit.transform.GetComponent(TextMesh);
       // if it's not a TextMesh, or if it's not an A...
       if (!txtMsh || txtMsh.text != "A"){
         score++; // increment the score
       }
     }
   }
 }
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 Em3rgency · Jul 08, 2013 at 08:46 PM

Start by doing the tutorials.

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 sharvari30 · Jul 08, 2013 at 09:20 PM 0
Share

Have gone through the Introduction and Scripting tutorials. How do I register the input when a mouse is clicked on a letter? Also, I used Text$$anonymous$$esh to display letters. Is Text$$anonymous$$esh called a GameObject?

avatar image Kiloblargh · Jul 09, 2013 at 06:25 PM 0
Share

No, it's a Component. Components are attached to GameObjects.

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

17 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

String array not working 1 Answer

How to convert a string to int array in Unity C# 1 Answer

convert string to list of lists 1 Answer

Array of Array 1 Answer

Is it possible to split a string without specifying a separator? 1 Answer


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