How can a single script is attached to multiple enemies/objects with separate behavior of every enemy

Hey guys, I am making a TD game and now stucked at multiple enemies using same script. All is well with scripts attached with one enemy only. Problem is in running multiple enemies.

Here is the overview. I have a Enemy object with which I have attached a ‘RunEnemy’ script. Flow of this script is:


    PathF p;
    p = gameObject.GetComponent<PathF>();     //PathF is a pathfinding algo which has 'search; function which returns a array of path from starting position					
	PathList = position);         				
	if(PathList != null) {                               //if a way found!		
    if(moving forward)    																
			transform.Translate(someXvalue,0,0);  //translates on every frame until next grid point
	else if(moving back)		

        ...and so on..

          if(reached on next point)
             PathList = this point)   //call again from next grid point so that if user placed a tower enemy will run again on the returned path


Now I have attached this script and “PathF.cs” to a single enemy which works perfect. I have then made one more enemy object and attached both of these script to it as well, which is not working they both are overlapping movements. I cant understand this thing, I have attached these scripts on two different gameobjects but still their values changes when either enemy changes its value. I dont want to go with separate script for each enemy bcz there wd be 30 enemies in a scene. Could someone give me solution that each enemy would use its own script or make its own copy or instance of that script ?? thnx.

Tag your enemies and then make any special handling/initialization for specific enemies in your Start() function switching between their tags. That way you can use the same script.

The same goes on Update() or any other function you need to have them act uniquely. Just switch between the tags.