- Home /
Need to check for presence of a prefab instance at a particular location.
I'm trying to have a top-down 2D map load in chunks, sort of similar to Minecraft. I want to always have the chunk the player is in loaded, along with all eight adjacent chunks. So, once it's determined that a player is inside (or above, rather) a given chunk, I want to have that chunk check each of the eight surrounding spaces for chunks and instantiate them where there are none.
Or in other words, if the player is anywhere in the chunk centered at (0,0) in world space, I want to check for chunks at (-1,1), (0,1), (1,1), (-1,0), (1,0), (-1,-1), (0,-1), & (1,-1), so I can then add any that are not present.
I'm coding in C#. I would think it would be simple to check presence with regard to location, and it probably is, but to my embarrassment, I can't seem to think of or find out how.
Alternatively, if there's a simpler or more efficient method for dealing with flat chunks like this, please let me know.
Are you are going to need to store a list or array of these somewhere so that you can delete the ones too far way? If so, just look through the list. If you really want to do it dynamically, you can use Physics.CheckSphere(), Physics.OverlapSphere, Physics.Raycast(), or Physics.Linecast().
Alright, well thank you, I think that solved that problem (I ended up using Physics2D.OverlapPoint), though I now have another problem involving colliders that I'm going to post as a separate question.
Your answer
Follow this Question
Related Questions
Combining if Statements 1 Answer
Single line if statement with many conditions or several single-conditioned if statements 1 Answer
C# the position of the object 1 Answer
Creating a Loadout 1 Answer
If gameobject moves do this 1 Answer