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 bol398 · Jan 09, 2017 at 03:15 PM · screenselectionrectcontains

Possible to return the names of gameobjects inside a rect?

As I said in the title, is it possible to create a rect and check which objects is inside it and return their names?

I tried using rect.Contains but couldn't get it to return the names, the only thing I was able to do was check IF an object is inside but not getting the name.

The reason I want to do this is because I want to make a selection box thing and then add the gameobjects inside the box to a list of selected units. Any help is appreciated :)

Comment
Add comment · Show 3
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 juicyz · Jan 09, 2017 at 07:26 PM 0
Share

If you can already check if an object is inside the rectangle, then you almost there. the psuedo code would look something like this.

 if object is in rect {
   if objects name is <insert> {
     <do something>
   }
 }

The way to get a name is using the GameObjects property of .name

avatar image bol398 · Jan 10, 2017 at 01:06 PM 0
Share

Sorry for the delayed answered, I think I'm going to rethink and try something different. Since rect seems to only use 2d positions making it hard for me to check if an object with a 3d position is inside.

I said before that I was able to check IF an object was inside, but that doesn't seem to be the case. However if you know how I'd go about checking 3d positions inside a 2d rect, feel free to help me. Otherwise I'm just going to try do insatiate a cube with a collider or something.

Thanks for the answers so far though

avatar image juicyz bol398 · Jan 10, 2017 at 04:43 PM 0
Share

That's how I would likely do it. It's simple and Unity handles everything for you in that case.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by grmlfimmel · Jan 09, 2017 at 05:07 PM

Could be that I get the question wrong but what about a Trigger/Collider on the rect and checking the Method OnTriggerStay(collider col) for the objects within the collider?

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

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Rect.Contains Screen Resolution Problem 3 Answers

Switching between multiple classes 2 Answers

Realtime object loading to scene 1 Answer

Rect.Contains not working 1 Answer

GUI label dimensions bug 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