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 /
  • Help Room /
avatar image
0
Question by Grego159 · Apr 02, 2016 at 07:17 PM · c#2djointsjointattachment

2D attaching Joint With Script ?

hi, 'm trying to Connect two 2d object with a C# Script , i have a Variable type Parts Gameobject[] ,adding the Parts Children, so i try link some objects to a Central object but i have a problem to get the Parts Childrens and do Link to the Central Object . Thanks to thoose who can help me :v

Comment
Add comment · Show 3
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 TX Manager · Apr 02, 2016 at 07:27 PM 0
Share

You mean you want to attach your objects together to become one object?

avatar image TX Manager · Apr 02, 2016 at 07:27 PM 0
Share

tell me, and I'll post the answer as needed

avatar image Grego159 · Apr 02, 2016 at 07:36 PM 0
Share

yes , think like a 2d ship building,that have parts to add to an Startin Block, and the player can Attach Parts in other parts.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by TX Manager · Apr 02, 2016 at 07:48 PM

There's really no way to attach 2 objects together using unity because it's not a software that works with the mesh or the sprites (Imported info) so you can decleer a new empty game object like this :- public GameObject parentObject = New GameObject (Vectro3, Vector3); set the transform as you like

public GameObject obj_1; public GameObject obj_2;

then set the 2 game objects to become Children of the parent obj

 `void Update ()
 {
 obj_1.transform.parent = parentObject.transform;
 obj _2.transform.parent = parentObject.transform;
 }`

if you are using a sprite software to make this 2D game, it will be best to use this way. if you are using Mesh in 3D or 2D game, so you better do it by your own by setting a new empty object in the scene and get one of those 2 objs to it then set it to the project asset folder then put the other object and then drag and put it again into the project asset folder,

this simple trick can attach them both. try it or see "how to save a prefab into a file in the window" to do this trick I told you in the docs : Windows - write all bytes I can't teach this thing because I didn't try it before

I hope this will help :)

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 TX Manager · Apr 02, 2016 at 07:51 PM 0
Share

tell me if it helped or try to tell me what you really want to know more about this

avatar image Grego159 · Apr 02, 2016 at 08:20 PM 0
Share

@TX $$anonymous$$anager here is a better explanation of what I'm trying to: alt text

avatar image TX Manager · Apr 02, 2016 at 08:31 PM 0
Share

this is very simple, I think.

1-set the sprite as a prefab on the Project

2-caluclate the distance between the 2 objects you want to connect like this :-

 void Update ()
 {
  vector3 distance = New vector3 (firstobj.transform.x - secobj.transform.x, firstobj.transform.y, secobj.transform.y, 0f);
 }


3-then Instantiate the prefab where it should be and calculate the scale by your own to know how scale do you want by the distance

I can't tell you more the details because I don't know the joint scale or how does it like

just calculate the distance then tell the computer in the script that the game object will be Instantiate between the 2 objects

"1.transform - 2.transform", then set the scale 2 eqal the

"1.transform - 2.transform * //the num you will know by your exper$$anonymous$$ts in the unity editor", I hope you will understand :)

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

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

How can I make HingeJoint2D more flexible? 0 Answers

How can make it so only 1 object of type “Ability” can be selected at once? 0 Answers

How do you compare multiple parts of the same array? 0 Answers

converting degrees per second into speed 1 Answer

How do I change the image of an SVG sprite? 0 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