Best way to assign a "Team" to an NPC

Hey guys! This is my first week working on Unity so I apologize if this question is obvious to some of you. I’m working on a game similar to clash royale, where both players have access to the same types of NPCs. And I dont know how to create a system so that the NPC knows which Player they belong to and who to attack.

I want each NPC to assign themselves to a RuntimeSet so its easier and optimized for enemy NPCs to find them, and vice versa. Right know I have a Scritable Object which contains a list of each category Runtime Set. For example: I have Player1Towers, Player1NPCs, Player2Towers, Player2NPCs. This way its easy for each NPC to find the closet target to move towards.
But since the Script running the NPC’s behavior has to be the same, regardless of which Player owns the NPC, i dont know how to implement it. Another issue is implementing the target preference system, for example I want some troops that only attack towers and others that attack both. But I run into the same problem as Im using a Universal Script Controller.

I was using a tag system for this and it was working fine, but I heard that finding GameObjects with tags is not ideal, and a RuntimeSet system would be better since each NPC wont be searching for the tag every frame.

Any help would be greatly appreciated !

The enemy can have a field on them that says which team they are. If you only have two teams, you can do something like:

public enum Team {

Which will give you a lot of clarity. Then the rest of the code becomes simpler as well;

// It's probably not named this, but...
public class NPC : MonoBehaviour {
    public NPCRegistry npcRegistry;
    public Team team; // assigned from the inspector
    public Team OppositeTeam => team == Team.Team1 ? Team.Team2 : Team.Team1;

    private void OnEnable() {
        npcRegistry.Register(this, team);

    private NPC FindClosestEnemy() {
        npcRegistry.FindClosestOnTeam(transform.position, OppositeTeam);

    // and so on

The NPCRegistry can be a ScriptableObject that contains a reference to all of the Runtime Sets you have defined, and grabs the correct one based on what team you’re asking for.