I'm making an RTS game in Unity with C#. However, the interaction I'm going to have with player-created units interacting with other player-created units is what has me stumped. The player and his opponent can purchase units when they have the resources, and it instantiates them in the game. The main thing is checking whether an opponent's unit is within range to attack. Obviously, you can't have every unit asking every other unit what its position is, or it would get exponentially more CPU-consuming the more units are built, right? I'm trying to figure out how I'm going to go about this.
I figured I could have every unit report its position to a sort of master 'tracker', and then every unit could ask the tracker if any opponents' units have a position within X of their own. How I would actually implement this in Unity, though, I'm not sure about.
Moreover, I'm trying to get my head around Instantiated objects. If every unit is telling its position to the master 'tracker', what does it call itself? And let's say a unit asks the tracker if an enemy is in range and one is, what does the tracker tell it so it can locate the right GameObject and attack it? Sorry if I'm talking about it all wrong, I'm sure there's a simple methodology that exists on how to do it, but I can't think of any. Thank you.