• 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 skyfire · May 31, 2013 at 12:30 PM · colliderboxpuzzlecollsionbridge

destroy all same color combination of bricks

Hi Everyone

I am making brick puzzle game.i am facing a problem please help me

alt text

you can see what type of project I am doing.Here is my question is whenever my ball collide or hit any red colored brick all the red colored brick which collide each other will destroy.i can't find any solution to do that.how i can destroy all the red colored brick which collide each other.Please suggest me the right ans. how i can destroy same colored combination of bricks.

and sorry for my English

thanks in advance

sa.png (58.7 kB)
Comment
Add comment · Show 5
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 rkaetano · May 31, 2013 at 03:11 PM 0
Share

I think that you could use raycast to all neighbours, and then check the render.material.color $$anonymous$$aybe this could works. ;)

avatar image Bloodyem · May 31, 2013 at 03:13 PM 0
Share

What is your code like? What you should be able to do is use a boolean as well, so it looks at whether or not the red ones are touching, and destroys them if they are, but I can't be too useful without your code.

avatar image HeavyPepper · May 31, 2013 at 03:30 PM 0
Share

If each brick is its own object it might be easier to assign a Tag and compare the Tag against collision. For example, give the red bricks a Tag of "red" so when you're checking for collision write an if statement to check if the collision object has a tag of "red", if so, destroy the game object.

avatar image Bloodyem · May 31, 2013 at 04:22 PM 0
Share

@AtomicPlatypus, If you do that, you would destroy every red object on the level at once, rather than just those that are touching. I think the OP just wants to destroy those that are touching.

avatar image HeavyPepper · May 31, 2013 at 05:45 PM 0
Share

@Bloodyem $$anonymous$$y intention was not to destroy by Tag but simply use the Tag to assess if a red brick was in the collision. You could then use what the collider is hitting to destroy that specific game object, not all red Tagged objects. Perhaps I wasn't as clear as I could have been. ;)

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by robertbu · May 31, 2013 at 04:22 PM

You could put something like this on all your boxes. Note it assumes that the boxes are tagged "Red" and "Green" for red and green boxes:

 #pragma strict
 
 function OnCollisionEnter(col : Collision) {
     if (col.collider.name != "Ball")
         return;
     
     var tag = gameObject.tag;
     
     var hit : RaycastHit;
     // Check the boxes above
     while(Physics.Raycast(transform.position, Vector3.up, hit)) {
         if (hit.collider.tag != tag)
             break;
         hit.collider.enabled = false;
         Destroy(hit.collider.gameObject);
     }
     // Check the boxes below
     while(Physics.Raycast(transform.position, Vector3.down, hit)) {
         if (hit.collider.tag != tag)
             break;
         hit.collider.enabled = false;
         Destroy(hit.collider.gameObject);
     }
     Destroy(gameObject);
 }
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 temptest123 · May 31, 2013 at 04:34 PM

doing anything with raycast here is overkill, this should be handled in the datamodel. Store references to your boxes in a 2D array for example (as you have rows of boxes). Or create a linked list implementation in which each box has a reference to the top and bottom box.

Comment
Add comment · Show 1 · 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 robertbu · May 31, 2013 at 04:55 PM 0
Share

Depends on the nature of the game and how the boxes are stacked. There won't be a performance issue with using raycasting for any reasonable number of boxes. And neither solution (raycasting or data model) would work well for some stacking scenarios.

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Internal collisions 1 Answer

2D box colliders gap 0 Answers

Multiple Colliders Trigger problem 2 Answers

Collider going through walls with box collider.. 1 Answer

why i can not destroy the collider 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges