Cannot use my combat script/ Object reference not set to an instance of an object

Fortunately I was able to get my last problem fixed with the enemy game object respawning when it’s not supposed to but now I have another problem. I know if I have a script with code that looks for a gameobject of tag enemy I need to have that tag listed or the code wont work. Problem is when I’m testing my hunt scout quest out, the code I have for combat isn’t working at all. What I find weird is that when I tag one of my other game objects to enemy it works fine but when none of them has the enemy tag on them, it doesn’t work. As for as the code the object reference is pointing to it is Vector3 dir = (enemy.transform.position - transform.position);. Should I assume that since that code is in there that I need a game object with a enemy tag? If I do what would be the best solution, I’m thinking maybe create an empty game object far enough away that it can’t be killed with an enemy tag on it or should I create a separate attack script for each combat quest?

Also I realize this is a separate question, and while my game is not close to being done and I’m going to explain this the best I can and I apologize for any confusion, but I’m also trying to find a way that when a person buys my game, they just can’t share the game with anyone else because the game key is already been used. For example lets say the Sims 4 Game requires a key to be installed, and once the game is installed if someone else tries to use that same key, the person will get a message stating, this key has already been used. I’m guessing that would be in the settings, but does anyone know how to get to that?

Thanks

if your code says “enemy is the object with a tag called enemy” an there isn’t any game objects with that tag, then “enemy” is then null, if your code tries to access some function/attribute/variable when the variable is null and there isn’t an instance of a specific object you’ll get an error. You don’t need to do anything like you’ve described.

You just need

GameObject enemy = GameObject.FindWithTag("Enemy");

if(enemy)
{
    // we have an enemy, can access it's properties, variables, functions etc.
}
else
{
    // we don't have an enemy
}