How to Instantiate a prefab with it's own variables?

Hello, I have a prefab called Enemy and it has a variable called EnemyHealth. When I use my Player Class to decrease that variable by attacking the enemy the variable changes on every Enemy so everyone gets killed. How do I decrease the Health of only the enemy I’m attacking? PS Im coding in C#

//Destroy enemy in range!
		Debug.DrawLine(InteractRangeStart.position, InteractRangeEnd.position, Color.green);

	if(Physics2D.Linecast(InteractRangeStart.position, InteractRangeEnd.position, 1 << LayerMask.NameToLayer("Enemy")))
	{
		Target = Physics2D.Linecast(InteractRangeStart.position, InteractRangeEnd.position, 1 << LayerMask.NameToLayer("Enemy"));
		interact = true;
	}
	else
	{
		interact = false;
	}

	if(Input.GetMouseButtonDown(0) && interact == true)
	{
		Enemy.EnemyHealth -= 5;

		if(Enemy.EnemyHealth <= 0)
		{
			Destroy(Target.collider.gameObject);
		}
	}

You have a number of things you will have to address. You will need to make ‘EnemyHealth’ not static. If they don’t already, your prefab will need a Enemy script attached. You will to use a version of LineCast that takes a RaycastHit parameter. You will need to use GetComponent() to get the specific Enemy health script from the object found by the Linecast().

http://docs.unity3d.com/412/Documentation/ScriptReference/index.Accessing_Other_Game_Objects.html

http://unitygems.com/script-interaction1/

Looking at your code you seem to have made ‘EnemyHealth’ a static variable. Static means one value is shared across all instances of that type (exactly your problem). First step, remove the ‘static’ for this variable. Now each instance of Enemy has it’s own unique health value.

To decrease the health of the specific instance you are hitting you need to work out which GameObject the Linecast actually hits, find it’s Enemy component, and then decrease the health on this specific object. So, Linecast returns a RaycastHit2D, which has a collider member. Get the colliders GameObject by writing collider.gameObject.

From here you get the Enemy component and then decrease the health.