Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by Kanami · May 07, 2014 at 02:02 AM · c#tagdrag and dropmatching

Matching objects using drag and drop

I am currently making a game where you have to match a term to a specific location on a field. The player will drag and drop, via mouse click, a term to the correct location on the field. I was thinking of doing a tag match between the object that will be the term and the plane that will be the location. Something like,

if gameObject.tag == gameObject.tag

do something (like score +1 or something)

However, I can't seem to figure out exactly how to code this. I'm new to Unity but understand c#. All in all, my question is how would I go about matching the tags of two objects?

Edit: This is the current code I have for drag/drop. It's just something I came across so nothing really set in stone.

 void OnMouseDrag () {
         point = Camera.main.ScreenToWorldPoint(Input.mousePosition);
         point.y = transform.position.y;
         transform.position = point
Comment
Add comment · Show 2
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 getyour411 · May 07, 2014 at 02:12 AM 0
Share

Do you have your drag/drop code already? The drag (mouseDown) event could be associated to a gameObject variable and the drop would be a different variable so the compare is if(gObj1.tag = gObj.tag)...; if you have your drag/drop, share it which should make this easier to answer

avatar image Kanami · May 07, 2014 at 04:45 AM 0
Share

Alright, duly noted. And if I understand correctly, the drop would have it's own variable separate from the drag? So I would need to rework my drag and drop code as well?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Noob_Vulcan · May 07, 2014 at 05:19 AM

 if (Input.GetMouseButtonDown(1)){

                         Ray ray = nGUICam.ScreenPointToRay (Input.mousePosition);
         
                                 RaycastHit hit = new RaycastHit ();
                                 if (Physics.Raycast (ray, out hit)) {
                                         
                                         if (hit.transform.CompareTag ("Your_Object_Tag")) {
                                                 pickedObject = hit.transform;
                                         }
                         
                                 } else {
                                         pickedObject = null;
                                 }

}

Now you have your pikedObject transform .Now do stuff in

 void OnMouseDrag(){
 //do stuff

 pickedObject.transform.position= Input.mousePosition;
 }
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.

Follow this Question

Answers Answers and Comments

21 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Finding transform.position of Object with specific Tag 0 Answers

About scene change: is my method bad programming? 1 Answer

Matching 4 specific object question 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