Making an attack function in C# for a 3D RPG game. Unity 5.5+

I need help with making my script work properly, I’ve got most of it working correctly but you can attack from anywhere in the world and hit the enemy. Help?

here is the full (non-working) code:

_

public class WeaponDamage : MonoBehaviour {

//Attacking
public float SharpnessOSword;
public float WeightOSword;
public float SpeedOSword;
public float EnchantednessOSword;

public float FinalAttack;

//Reload
public float attackTimer;
public float coolDownTimer;

//Who to attack
public GameObject Enemy;

void Start() {

	//Attack
	FinalAttack = (SharpnessOSword * EnchantednessOSword * SpeedOSword) / WeightOSword;

}

void Update () {

	//Cooldown and attack
	if (attackTimer >= 0) 
	{
		attackTimer -= Time.deltaTime;
	}
		

	//Modified Code
	//Works Partially needs collider
	//if (Enemy.gameObject.name == "Enemy") 
	//{
	//	if (Input.GetKeyDown (KeyCode.O)) 
	//	{
	//		Enemy.gameObject.GetComponent<EnemyHp> ().EnemyHP -= (SharpnessOSword * EnchantednessOSword * SpeedOSword) / WeightOSword;
	//		attackTimer = coolDownTimer;
	//	}
	//}

	//Slightly More Modified Code
	//Needs collider now
	if (attackTimer <= 0) 
	{
		if (Enemy.gameObject.name == "Enemy") 
		{
			if (Input.GetKeyDown (KeyCode.O)) 
			{
				Enemy.gameObject.GetComponent<EnemyHp> ().EnemyHP -= (SharpnessOSword * EnchantednessOSword * SpeedOSword) / WeightOSword;
				attackTimer = coolDownTimer;
			}
		}
	}

	//Older Code
	//if (Input.GetKeyown (KeyCode.O)) 
	//{
		//if (attackTimer <= 0.1) 
		//{
			
			//if (Enemy) 
			//{
				//Enemy.gameObject.GetComponent<EnemyHp> ().EnemyHP -= (SharpnessOSword * EnchantednessOSword * SpeedOSword) / WeightOSword;
				//attackTimer = coolDownTimer;
			//}
		//}
	//}
}

}

No one is replying so Bump.