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 /
avatar image
0
Question by stspy212 · Feb 19, 2016 at 01:43 PM · tagsdrag-and-droptagging

Drag/drop potentially unlimited generated "creep" objects, but one at a time

What I currently have is a script to drag a 2D sprite. The problem is, the script runs off of the object to be dragged's tag.

However, If I have, for example, seventy of these same objects, then clicking and dragging on one will drag all objects with that tag.

To be more specific, my end-goal is to have potentially endless creeps (meaning several duplicates) spawning. clicking on any one creep and dragging it will only drag that one creep. Will I need a ton of tags to achieve this or is there a better way?

Here is my current code. If you reply with code, feel free to use either javascript or C#, I'm not picky.

Thanks for your input(s)!

 #pragma strict
 
 
 function Update ()
 {
     if (Input.GetMouseButton(0))
     {
         var hitInfo : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
  
         if(hitInfo.collider.tag == "Guard")
         {
             
             this.transform.position.x = hitInfo.point.x;
                this.transform.position.y = hitInfo.point.y;
             Debug.Log("object clicked: "+hitInfo.collider.tag);
         }  
     }
 }
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 Teravisor · Feb 19, 2016 at 04:56 PM 1
Share

What I see in your code is it sets position of this object to place where you clicked on object with Guard tag.

You are only picking one object, checking if it has "Guard" tag, and doing something. If you click on object without "Guard" tag it won't do anything. If you click on several objects with "Guard" tag only one will respond to that click.

You don't need that $$anonymous$$onoBehaviour on all creeps. Ins$$anonymous$$d, you need your camera(or some neutral single object) to check if you clicked on Creep and get it if you did.

avatar image stspy212 Teravisor · Feb 19, 2016 at 10:01 PM 0
Share

Interesting. I can't believe I didn't think of this. Thank you very much!

0 Replies

· Add your reply
  • Sort: 

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

nullReferenceException when comparing tag in a search for a specific parent. help. 1 Answer

Are Tags the best solution for this? Duplicating an item that duplicates itself a set amount of times. 1 Answer

How can i destroy spawned objects according a indicator? 2 Answers

Destroying Multiple Objects with Tags 1 Answer

Delete some unused tags and game objects tag changes unity 5 2 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