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 Orange90 · Dec 17, 2013 at 07:37 AM · gameobjectdistancevector

Detect if game object is near a specific tag

How can I detect if my game object (player) is near an object with a specific tag?

I can detect single objects like this:

  float distance = Vector3.Distance (plyr.transform.position, transform.position); 
     if (distance <= maxRange) {
     GameObject.Find ("Action Text").guiText.text = "Press (E) to interact";
     }

But what about multiple objects based on their tags?

Comment
Add comment · Show 1
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 el-santia93 · Dec 17, 2013 at 07:50 AM 0
Share

you could always use triggers invisible cubes the player could detect

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Briksins · Dec 17, 2013 at 12:54 PM

you can check against each of them in the loop, here is a logic

  1. Use Unity FindGameObjectsWithTag

  2. You will get array of object (obviously if they found)

  3. check the distance from player to those objects

  4. if distance in range of

  5. Then user is close to particular object from all of those in array

But it is not good implementation as it is very compute intensive, as basically each update you will have to find all those objects, calculate distance to them compre if distance is in range of "close range" and blah blah blah

What you should do is to attach to each of your objects collider and trigger an event from exact object once it collide with Player you can set to player - "Player" tag and on collision event check if collided object is player then allow to player to do whatever you want with that object which triggers that is optimal solution

Comment
Add comment · Show 1 · 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 Orange90 · Dec 17, 2013 at 02:52 PM 0
Share

Thanks, I thought that objects with a standard collider can't have another trigger collider, that's why I tried it the hard way.

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

19 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

Related Questions

Finding Nearest Object Both Positive And Negative? 1 Answer

Hexagon-Grid Distance 2 Answers

iTween MoveTo "Convoy" 0 Answers

grab all game objects with a distance of the object? 2 Answers

OnMouseOver Distance Measuring 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