• 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 Ertunc · Sep 12, 2017 at 02:47 PM · collisiontriggerchild objectsnapping

Snap with collision trigger on child objectss

I want to add a snap option to two parent objects with their childs. The collison is 2D with trigger. Non-collided state is as belows: alt text

After collison, i change the color of the part to green with:

void OnTriggerEnter2D(Collider2D other) {

     if (other.gameObject.tag == "Board")
     {
         
         
         other.GetComponent<Renderer>().material.color = Color.white;
         GetComponent<Renderer>().material.color = Color.green;
        

      
     }
 }

Then the state becomes as belows:

alt text

What I want to do is,if every part is green, on double click, keypres or whatever, I want to change all collided childs position to other collided objects position ( snap )

I can check the situation if everypart is green with :

    foreach (Renderer r in GetComponentsInChildren<Renderer>())
     {
         if (r.material.color != Color.green)
         {
             //do action

         }

The point I am stuck is to check the collision state of each component and equalize them to collided parts.

I would appreciate your help on the subject.

Thank you.

no-touch.jpg (10.5 kB)
touch.jpg (10.4 kB)
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by tormentoarmagedoom · Sep 13, 2017 at 08:29 AM

Good day @Ertunc !

Well, i'm not sure what you want to do. You want to change the worldPosition of the childs? or what you want is to change the parent of the childs and of course move it to correct the new parent position?

I supose you want the child/parent change. Let's see then.

Lets make a GameObject variable called Sphere to refear an object called GOChild which is the child of the gameobject GOParent, using the transform.Find to look for childs

 Shpere=GOParent.transform.Find("GoChild");

Now, lets change the parent of the Sphere, to become the child of an object called GOParentTwo

 Sphere.transform.parent = GoParentTwo.transform

Now, the sphere is a child of the GOParentTwo, but you need to move it where you desire with the Sphere.transform.LocalPosition.

If what you want i to check if each sphere is colisioning, you must do it 1 by 1 with a script placed in each sphere with the OnTriggerEnter and checking the other collider.gameObject.transform.parent is another gameObject.

If this helps upvote !!

If is not what you asked for, just ask again, give more info, and use @tormentoarmagedoom !

Bye:D

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

115 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 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 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 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 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 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 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

OnTriggerEnter Being Called On Unexpected Object 1 Answer

How to call OnTriggerEnter once 5 Answers

Stacking mechanic (Parenting Prefab to another prefab on collision) 2 Answers

Collision vs trigger 1 Answer

Change NavMesh Speed after collision/trigger just for 1 object 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