I have two different objects that I would like to attach together, in such a way that if one moves, the other does as well and vice-versa. Parenting doesn't work, because it doesn't go both ways. I don't want to create an parent empty game object that overlaps the two other objects since it is very important that the user can chose which object he wants to have as a reference to movement.
Thank you very much
Answer by syclamoth
Dec 22, 2011 at 01:25 AM
Sorry about my previous post, that was a stupid way to do it.
You should make both objects children of a single empty, and always use that for movement. Your comment about wanting to chose which object the user wants a reference to isn't exactly a valid one- the end user doesn't know anything about how it works internally, so all you have to do is make sure that any time they would translate one of the objects, instead translate the parent object. I really don't see why you can't do it this way- it's simple, and guaranteed to work.
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
If you are a new user, check out our FAQ for more information.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
For troubleshooting common problems with Unity 5.x Editor (including Win 10).
To help users post good questions and use the site effectively we have posted a user guide. Please check it out.
Answers and Comments
6 People are following this question.
Can I use AddComponent to add (this.script) to an object?
C# how to attach a material to a gameobject?
GO.AddComponent just adds an empty Script
How to attach a mesh created with Graphics.DrawMesh to a GameObject?
C# Scripts don't attach to game objects, what happened?