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 jeremyn · Jun 17, 2015 at 07:07 PM · c#2dscriptingbasics

How can I compare a sequence of GameObjects when tapped?

I've create a list of GameObjects A to Z. They're then picked randomly and displayed on a 2D grid.

Next, I want to be able to tap the GameObjects in sequence A to Z.

How can I compare the list of GameObjects to know that the sequence is correct when tapped?

Originally I tagged each alphabet prefab as "A" to "Z", but since I needed to count the length, I changed the tag to "Alphabets". However, I now cannot destroy the object based on tag A - Z, and am trying to use the object name instead. It doesn't seem to work.

Thank you.

 void OnMouseDown()
     {
         GameObject[] alphabetCount;
         alphabetCount = GameObject.FindGameObjectsWithTag("Alphabets");
         if(alphabetCount.Length == 26){
 
             if(this.object.name("A")){
                 {
                     Destroy (this.gameObject);
                 }
 
             }
         }
     }

Comment
Add comment · Show 1
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 Eno-Khaon · Jun 21, 2015 at 07:28 PM 0
Share

Just to note: Based on the general presentation for an object's name, it appears that your if statement might work if formatted as:

 if(this.object.name == "A")

I would presume, from the way you assembled it in your example, that you might have originally been using CompareTag(), which would be the faster way of testing a tag's name, but is only relevant to using tags.

1 Reply

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

Answer by fafase · Jun 18, 2015 at 11:04 AM

every time you tap an object run the check:

 GameObject[] original = new GameObject[]{ // Define your sequence};
 List<GameObject>list = new List<GameObject>();
 bool CheckSequence()
 {
    for(int i = 0; i < original.Length && i < list.Count; i ++){
        if( original[i] != list[i] ) { return false; }
    }
    return true;
 }

Now it also depends on what you are meant to check so you change the if section to what you need.

the CheckSequence gets call on touch of a game object.

 void OnMouseDown()
 {
     bool result = CheckSequence();
     Debug.Log("Sequence is " + result.ToString());
 }
Comment
Add comment · Show 3 · 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 jeremyn · Jun 19, 2015 at 05:46 AM 0
Share

Thanks! I've been trying and I'm not too sure with the sequence part as I get an error.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic; 
 
 public class Input$$anonymous$$anager : $$anonymous$$onoBehaviour {
 
     GameObject[] original = new GameObject[]{"A","B","C","D","E","F","G","H","I","J","$$anonymous$$","L","$$anonymous$$","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
     //Tile$$anonymous$$anager.alphabetTilesList;
     //new GameObject[]{"A","B","C","D","E","F","G","H","I","J","$$anonymous$$","L","$$anonymous$$","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
     List <GameObject> alphaCheckList = new List <GameObject>();
 
     bool CheckSequence()
     {
         for(int i = 0; i < original.Length && i < alphaCheckList.Count; i ++){
             if( original[i] != alphaCheckList[i] ) { return false; }
         }
         return true;
     }
         
         
         void On$$anonymous$$ouseDown()
     {
         bool result = CheckSequence();
         Destroy (gameObject);
     }
 }

Actually I've created the list in another script

Tile$$anonymous$$anager.cs as

 public List <GameObject> alphabetTilesList = new List <GameObject> ();  //A list of alphabet tiles.

I tried using the list in the above example: GameObject[] original = Tile$$anonymous$$anager.alphabetTilesList; which I will then get a different error: error CS0236: A field initializer cannot reference the nonstatic field, method, or property `Tile$$anonymous$$anager.alphabetTilesList'

Which is the best way to solve this error?

avatar image fafase · Jun 21, 2015 at 07:15 PM 0
Share
 GameObject []original ;
 
 void Start(){
    original = Tile$$anonymous$$anager.alphabetTilesList;
 }
avatar image jeremyn · Jun 22, 2015 at 03:37 AM 0
Share

Thank you!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Lasers wont stop firing?? 1 Answer

Particle System On Key Press 2 Answers

How do I make a prefab ignore collisions with another prefab temporarily. 2 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