Check Distance | Duplicate Object

Hello,

I am trying to check for a distance on an object, however there are two instances of the same object. I’ve gotten the code down for one instance, I can’t figure out how to check for the other.

Thanks.

One simple option would be to create 2 identical scripts with different variables (i.e. Object1, Object2) and attach them to both objects. It creates more variables and uses and extra script, but it’s the simplest solution.

1 Like

Thank you!

Seems quite painful to me. Especially if you go on to create three or four or fifty objects.

How would you solve it?

I need some more meta data first. What are the objects, how far apart are they, how often do you need the check, why do you need the check ect.

If it’s only ever these two objects, then a single script with a drag and drop reference to both objects will do fine.

Wood is the object. Since there will be many, I want the player to be up close enough to a point where he/she can break it. I was going to have it highlight as well, but I couldn’t figure that out. Something to do with Shaders.

I’d put a trigger collider on your player or wood with the range for the object. Then in OnTriggerEnter you can do whatever you like with the wood.

That way you can take advantage of PhysX’s space partitioning.