How do you target instantiated Objects without using tags???

Hello,
I have a spawning script for my enemies and they can attack me but I can’t attack them.
I have tried using tags but that has not worked. Could some one PLEASE help me.
My attack script is in C Sharp.

Here is my player attack script (No attack method included.):

using UnityEngine;
using System.Collections;

public class PlayerAttack : MonoBehaviour {
public GameObject target;
public float attackTimer;
public float coolDown;
public GameObject Original;

// Use this for initialization
void Start () {
attackTimer = 0;
coolDown = 0.0f;

}

// Update is called once per frame
void Update () {

if(attackTimer > 0)
attackTimer -= Time.deltaTime;

if(attackTimer < 0)
attackTimer = 0;

if(Input.GetKeyUp(KeyCode.E)) {
if(attackTimer == 0) {
animation.Play(“slashing_motions”);
Attack();
attackTimer = coolDown;
}
}

}

private void Attack() {

float distance = Vector3.Distance(target.transform.position, transform.position);

Vector3 dir = (target.transform.position - transform.position).normalized;

float direction = Vector3.Dot(dir, transform.forward);

if(distance < 2.5f) {
if(direction > 0) {
EnemyHealth eh = (EnemyHealth)target.GetComponent(“EnemyHealth”);
eh.AddjustCurrentHealth(-15);
}
}

There’s a couple ways you could do it. When you spawn your enemies, you could add them to an array that can give a reference to the enemy, or you could cast a ray out from the center of the player and get the game object of whatever it hits. (then you’d need to use a tag or something to make sure it’s an enemy) and get the game object from that

you could also check for the existance of a certain component at the gameobject you want to attack. do a getcomponent fe and check the reutrn value to be nonzero. then you a have a gameobject with an attack script attached.
but you need the gamobject to attack to find. look here: http://forum.unity3d.com/threads/119447-Clicking-on-an-enemy-to-target-him

Where is the code you use for instantiating enemies?

Well, the spawning is is way too big to post so I’ll show you the Enemy Health if that helps…
Also, I am kinda new to scripting so I can’t understand everything, could you please try and keep it simple.

Here is the Enemy Health Script:

using UnityEngine;
using System.Collections;

public class EnemyHealth : MonoBehaviour {
public int maxHealth = 50;
public int curHealth = 50;

public float healthBarLength;

// Use this for initialization
void Start () {
healthBarLength = Screen.width / 1;
}

// Update is called once per frame
void Update () {
AddjustCurrentHealth(0);

if(curHealth < 10)
{
animation.Stop();
animation.CrossFade(“Death01”);
gameObject.SetActiveRecursively(false);
Destroy (gameObject);
}

}

public void AddjustCurrentHealth(int adj) {
curHealth += adj;

if(curHealth < 0)
curHealth = 0;

if(curHealth > maxHealth)
curHealth = maxHealth;

if(maxHealth < 1)
maxHealth = 1;

healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
}
}