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 Sendatsu_Yoshimitsu · Aug 03, 2014 at 08:04 AM · c#colliderbounds

Bounds.Contains not working properly

I have a RoomManager script whose job is to track and manipulate all objects inside the room, which is defined by a box trigger collider that the script requires. Every piece of furniture has a collider, and I'm trying to iterate through my furniture and compile a list of every piece inside the collider, as follows:

 furnitureHolding = GameObject.FindGameObjectsWithTag ("Furniture");
         for (int i = 0; i < deskHolding.Length; i++) {
             if (Bounds.Contains(furnitureHolding[i]))
                 furnitureList.Add(furnitureHolding[i]);
 
         }

However, the line with Bounds.Contains prompts an error, "An object reference is required to access non-static member UnityEngine.Bounds.Contains(UnityEngine.Vector3)". Is my syntax somehow off, or am I just using bounds.contains in a way it wasn't intended for?

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

3 Replies

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

Answer by dsada · Aug 03, 2014 at 09:20 AM

Contains is not a static function of the Bounds class. You are trying to use like it was. You need a Bounds instance and then you can call that. You said you have a collider so i will assume you are using the collider's Bounds. In this case you should do this:

 Bounds myBounds = yourCollider.bounds; //yourCollider here is the collider your script requires.
 
 furnitureHolding = GameObject.FindGameObjectsWithTag ("Furniture");
         for (int i = 0; i < deskHolding.Length; i++) {
             if (myBounds.Contains(furnitureHolding[i]))
                 furnitureList.Add(furnitureHolding[i]);
  
         }
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 Sendatsu_Yoshimitsu · Aug 03, 2014 at 10:17 AM 1
Share

So this gets rid of the error, and fixing the typo mentioned in the post below everything works 100% perfectly- thank you so much for the clarification! I had mistakenly assumed that Bound was a function, not a type.

avatar image
0

Answer by Taylord303 · Aug 03, 2014 at 09:51 AM

I haven't used bounds much, but I believe it is supposed to be used Collider.bounds.

Comment
Add comment · Show 2 · 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 flaviusxvii · Aug 03, 2014 at 01:04 PM 0
Share

Saying nothing is better than saying something wrong.

avatar image Taylord303 · Aug 03, 2014 at 10:52 PM 0
Share

I'm sorry, I'm just trying to help. There's no need to be rude. If you have some great input, please, present it. Otherwise, there is no need for you to comment.

avatar image
0

Answer by gjf · Aug 03, 2014 at 09:23 AM

what type is furnitureHolding defined as?

Bounds is a type - you need a variable containing the bounding box.

 Bounds boundingBox = new Bounds(Vector3.zero, new Vector3(1, 2, 1));

then

 if (boundingBox.Contains(furnitureHolding[i]))

you are iterating thru furnitureHolding using deskHolding.Length as a count - that's an accident waiting to happen ;)

also, which line is the error reported on?

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

24 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

Related Questions

How to diable colliders after scoring point 1 Answer

How to transfer colllider from OnTriggerEnter to Update 1 Answer

Storing collided gameObject array index 1 Answer

Pausing a game using colliders 0 Answers

Can't transfer colllider from OnTriggerEnter to a public bool 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