I am following this video tutorial on how to implement drag-to-select behavior like in an RTS. The only difference is, I'm using a tilemap.
The selection area is a square which I can drag to make it as big as I want, like in any top down RTS.
CodeMonkey in his video uses
Physics2D.OverlapAreaAll to get a list of all colliders in the selected area. I want to use this to specifically see which "vegetation" tiles I've selected. However, no matter which vegetation tile I select, or how many, I always get one result - the vegetation tilemap itself.
You can clearly see from this picture that every grass tile and every tree tile have a collider around them, which is why this works, but how can I get exactly those that I selected?
Other than vegetation from the tilemap, I also want this to work with GameObjects that have Box2DColliders on them, and that works out of the box. I also made those MonoBehaviors inherit an interface called
ISelectable, so I can only add to the selected list entities that have that inherit that interface. I tried to do the same with vegetation like so
public class Vegetation : Tile, ISelectable but it doesn't work.
What am I missing? Can this even work on a specific tile basis?