#So I’m trying to figure out how lists work and I can’t figure out how to use them to do what I want.

1 messages · Page 1 of 1 (latest)

azure bramble
#

1 - I want to make a list of all game objects with a certain tag that are close and in view of the camera. I know how to check if an object is close and in view of the camera when I have a set GameObject variable I can check, but I don't know how to add multiple objects to a list based on that.

2 - I also need to find which object in the list has the lowest or highest x or y value on this Vector3 “Vector3 directionOfObject = transform.InverseTransformPoint(theObject.transform.position);” which is based on their position, and be able to set a “GameObject” variable equal to that object.

Can anyone help me?

Also I don't know if this is important but this script is connected to the camera.

versed fulcrum
#

Seems like you just don't know how to make a list if you're saying you can do the rest of that

#

why not just look at documentation?

azure bramble
#

I cant find the documentation for lists for some reason and I do know how to make a list and add and remove items from it but I'm not sure how to find the objects I want to add without just repeating adding the same object a bunch of times

azure bramble
#

I think I've figured out how to add many objects at once without repeating one, but I don't know how to check if any of the objects I'm adding are near/close or in camera/out of camera
does the way I'm trying to do this make sense?

#

I put "specifideTarget" and "specifideTargetCollider" as placeholders to give an idea of what I want to do

wanton hound
azure bramble
#

I suppose something like this makes more sense?

wanton hound
#

Yep. That should be better.
Though you'll get runtime errors, since you're removing from a list thta you're iterating on.

azure bramble
#

oh yeah that makes sense

wanton hound
#

You need to iterate it backwards.

azure bramble
#

wait no I think I see how

#

like this?

#

or wait maybe more like this I think

wanton hound
#

Count - 1, since it's 1 based, not 0 based as indices.
And i >= 0, as you want to check the element at index 0 too.

azure bramble
#

For some reason its just getting rid of all the objects in the list even if neither of the requirements are true. I checked with each of the requirements off and its the same for both. and I tried getting rid of the part that removes the object from the list and the adding part definitely works

#

wait I think im just dum

wanton hound
#

One of them is probably true.
Use a debugger to step through the code or add some logging to see what's going on.

azure bramble
#

I put < instead of > on the first one

#

likely something similar for the other one

#

ok yeah I forgot to put this line of code before that
"planes = GeometryUtility.CalculateFrustumPlanes(cam);"

#

Ill try to do the rest of what I was trying(I think I might be able to figure it out now) and ask another question if I need help. Thank you for helping me