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 CleeDotExe · Oct 12, 2021 at 10:10 AM · unity 2d

Find object with tag in small distance and delete found object and itself.

Hello! So I have this code, that randomly spawns pipes and then deletes the transform it spawned at, so that something doesn't spawn there again, this works. There is a problem, however:

If there is a pipe with 4 openings, when spawned that would leave 3 openings. The problem here is that it doesn't check if there is a connection (So with tags, for example Right would connect to Left)

How do I check if there is something in range, while also not checking the whole world for objects with some tag, then check if one of those are in range. I don't want this because it is inefficient, logical I hope? I cannot check if there is ANY sort of pipe in any direction, because some pipes don't have a connection that way, and that would leave an open pipe.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by logicandchaos · Oct 12, 2021 at 02:25 PM

You can use OverlapCircleAll for 2d or OverlapShereAll for 3d then you check the tags, then delete the object.

Alternatively you could use FindGameObjectWithTag and then check the distance with Vector2.Distance for 2d or Vector2.Distance for 3d.

I think the 1st may be more efficient, but really depends on a lot of factors.

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 CleeDotExe · Oct 12, 2021 at 03:30 PM 0
Share

Thanks, I'll try this out! I'll put out an update.

avatar image CleeDotExe · Oct 12, 2021 at 08:43 PM 0
Share

Alright, so I figured that just using this:

 void OnTriggerStay2D(Collider2D col)
          {
                  Destroy(col.gameObject);
          Destroy(gameObject);
          }

Would work, only it doesnt. Would you have any clue why? alt text

The colliders are on each of those children (The ones with anchors), using this should destroy bottom and right transforms? The top one is gone, because that is where it spawned.

capture.png (14.5 kB)
avatar image CleeDotExe · Oct 13, 2021 at 07:57 AM 0
Share

I found the answer! I thought something was wrong with my colliders, but no, it was them defor$$anonymous$$g and not touching because they were anchored children.

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

134 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

Related Questions

Unity 2D - Pivot points based on slice, not on original texture. 0 Answers

Camera Effects for 2d 0 Answers

Unity 4.3, generate 2d mesh 2 Answers

2D C# Jump Script Addforce 2 Answers

Is there any way of creating primitive 2D shapes in unity? 1 Answer


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