Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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
1
Question by Clunk · Oct 02, 2011 at 05:15 PM · collisionpuzzlematch

Match 3 objects and destroy!?!?!

I cannot get my head around this one. I simply want to match 3 objects of the same type and destroy them all once there are 3 connected. I have tried parenting and destroying when childCount == 3. I have tried fixedJoint.connectedBody. I have tried OnCollisionEnter, if tags are equal, count+=1, if(count>=3), etc.... It works on some connections, but not most. Here is the code I have so far, this one works the best out of what I have tried. Next I will try Raycast, but I want to find if anyone can help w/ this. I have 3 cubes just for testing. They are 1 Red, 1 Green, 1 Blue cube, tagged R, G, and B. They are all non-kinematic rigidbodies, as well as box colliders.

var count : int = 1;

function OnCollisionStay (collision : Collision)

{

 if(collision.gameObject.tag == gameObject.tag)

 {

     count+=1;

     collision.transform.parent = transform;

 }

 

 if(transform.childCount >= 2 && count>= 3)

 {

     Destroy(gameObject);

     count = 1;

 }

 



}

Comment
Add comment · Show 6
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 Julien-Lynge · Oct 02, 2011 at 05:23 PM 0
Share

@Clunk

What you want to do sounds very reasonable, but I just need a bit more information before I can help you. The question I have is: what are the conditions under which you want to destroy the three objects? And related: how do you know which 3 objects to destroy?

For instance, 'I want to destroy 3 cubes when they collide with the player. The 3 cubes are all children of the same object.' Or: 'I want to destroy the closest 3 cubes to the player every 10 seconds.'

avatar image Clunk · Oct 02, 2011 at 07:10 PM 0
Share

It is a tetris style Drop, I made it where a random cube is picked to drop at a random position offset. When 3 cubes of a kind are of the same color, I want all 3 to be destroyed. I have everything working as far as how to detect what cube is what color. The blue cubes only destroy if they touch 2 other blue cubes. Same w/ red and green cubes. It's just that sometimes it works, but it doesn't work if they match vertically or horizontally. It only works if they are in an L shape, like one cube in the center, and a cube on the top or bottom, and another on the right or left. This is because the corners of all 3 cubes are touching, or colliding. In other words, if there are 3 in a row veritcally or horizontally, it doesn't work, because it only works if they are all 3 colliding w/ each other at once. I hope I explained this well enough to understand. It's like the count+1 variable adds up no matter where collisions occur. Should count be a static variable?

avatar image mogambo · Jan 05, 2014 at 04:44 PM 0
Share

Thanks a lot $$anonymous$$r Clunk. You saved my life in a way. your question is very helpful to me. i could not answer your question though. But, your post solved my similar other problem.

avatar image baris150490 · Jan 05, 2014 at 05:00 PM 0
Share

You are 3 years late mate to thank

avatar image aristaios · Jan 05, 2014 at 05:11 PM 0
Share

What a bump! Would be interesting to know if you got your head around the problem baris150490.

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

7 People are following this question.

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

Related Questions

Columns/Magic Jewelry remake on Unity 0 Answers

Pattern Detection 1 Answer

Child object getting transformed out side the scene on collision? 1 Answer

Pixel perfect Collision? 0 Answers

"Collision" between UI images 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