help with enemy targeting system(lock on)

Hello guys, I am new to learning unity. I am having a bit of a difficult time trying to get my player to target the enemies. Ill upload my script, if anyone can help it will be greatly appreciated.

public class TargetingScript : MonoBehaviour {
int current = 0;
bool locked = false;
public CharacterController PlayerController;
public GameObject enemyLocations;
public GameObject closest;
public Transform activeIcon;
public float smoothTime = 1.0f;
public Transform meTransform;

// Use this for initialization
void Update()
{
PlayerController = (CharacterController)GetComponent(typeof(CharacterController));

if (closest != null && locked)
{
	activeIcon.gameObject.active = true;
	activeIcon.transform.position = new Vector3(closest.transform.position.x,closest.transform.position.y+0.3f,closest.transform.position.z);
}
else
{		
	activeIcon.gameObject.active = false;
}


if(Input.GetButtonDown("Lock")) 
{		
//Looks for the closest enemy

FindClosestEnemy();
locked = !locked;

//playerController.lockedon = !playerController.lockedon;

}	

if(locked) 
{
	//If there aren't any enemies (or the player killed the last one targeted) make sure that the lock is false
	if (!closest)
	{		
		activeIcon.gameObject.active = false;
		//playerController.lockedon = false;
		locked = false;
		closest = null;
	}
	
	//if (playerController.isAttacking || playerController.isAirAttacking)
	//{
		//transform.LookAt(Vector3(closest.transform.position.x, transform.position.y, closest.transform.position.z));
	
    Vector3 rushDirection = meTransform.transform.forward;
	
//		Rush(rushDirection);
//	}
	
}

}

IEnumerator Rush(Vector3 rushDistance)
{
//The length of time that the player will be rushing
float rushTime = Time.time;

		while (rushTime+smoothTime > Time.time)
		{
			transform.LookAt(new Vector3 (closest.transform.position.x, transform.position.y, closest.transform.position.z));
				
				float dist = Vector3.Distance (closest.transform.position, meTransform.transform.position);
	 			Debug.Log(dist);
	 			if (dist > 3)
				{PlayerController.Move(rushDistance*(rushTime+smoothTime-Time.time)/smoothTime*Time.deltaTime);}
			 yield return true;
		}

}

GameObject FindClosestEnemy ()
{
// Find all game objects with tag Enemy
enemyLocations = GameObject.FindGameObjectsWithTag(“Enemy”);
//var closest : GameObject;
float distance = Mathf.Infinity;
Vector3 position = transform.position;
// Iterate through them and find the closest one
foreach ( GameObject go in enemyLocations)
{
Vector3 diff = (go.transform.position - position);
float curDistance = diff.sqrMagnitude;

		if (curDistance < distance) 
		{ 
			closest = go; 
			distance = curDistance; 
		} 
	} 
return closest; 

}

}

Here’s a tutorial about targeting :wink:

Thanks DanTheMan, this helped out a lot.