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*))*
_ furnitureList.Add(furnitureHolding*);*_
* }* 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?
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*))*
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*))*
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?