• 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 JapPark · Dec 03, 2016 at 09:34 AM · objectobjectsattachconnectput

How can I attach objects like a picture?

I wanna attach an object to another like a picture, when I drag an object near another. I searched and found some information.

ex) obj1.transform.parent = obj2.transform; obj1.transform.localPosition = Vector3.zero; obj1.transform.localRotation = Quaternion.identity;

But, It makes objects overlapped. How do I do?... can anyone help me please?

1.png (7.6 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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Paricus · Dec 04, 2016 at 10:58 AM

I'm not entirely sure what you're trying to do. At the moment it seems like you're just moving one object to another objects position, the reason they overlap is because you're telling them to share the same coordinates. There's a number of ways to make them sit next to each other, but it'll get more complicated the more complex your objects get. for now just try getting the scale of the object you're moving to and offset the first objects position by half of that scale.

  obj1.position = obj2.position;
  obj1.position.x/y/z += (obj2.localscale.x/y/z + obj1.localscale.x/y/z)

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 Cherno · Dec 04, 2016 at 06:35 PM

You can use this shader which offsets the drawn texture so that it is drawn a tiny bit more towards the camera, to solve the overlapping issue. Great for decals.

 Shader "Custom/BlendedDecal"
 {
     Properties
     {
         _Color ("Tint", Color) = (1,1,1,1)
         _MainTex ("Texture", 2D) = "white" {}
     }
     
     SubShader
     {
         Lighting Off
         ZTest LEqual
         ZWrite Off
         Tags {"Queue" = "Transparent"}
         Pass
         {
             Alphatest Greater 0
             Blend SrcAlpha OneMinusSrcAlpha
             Offset -1, -1
             SetTexture [_MainTex]
             {
                 ConstantColor[_Color]
                 Combine texture * constant
             }
         }
     }
 }
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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Attach object when NOT in Hierarchy 1 Answer

Counting active objects in a list 3 Answers

onmousedown on object teleport 1 Answer

What are GameTiles? 1 Answer

Attaching a Camera to the Player 3 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