One Game Object getting Closer to another Game Object

Hello, I am relatively new to programming in unity and I am lost in how to make one game object get closer to another game object. I feel this is pretty basic but apparently I’m not grasping it quite yet. I’m trying to place this script into the enemy that will be chasing the player.

If people could help me I would be very appreciative, thanks in advance.

Here are some codes I’ve been working on:
public class EnemyAIMelee : MonoBehaviour
{
public GameObject playerCharacterManager;

	void Start()
	{
		playerCharacterManager = GameObject.FindGameObjectWithTag ("PlayerCharacterManager");
	}

	// Update is called once per frame
	void LateUpdate () 
	{
		MovingAI ();
	}

	void MovingAI()
	{
         //Move towards playerCharacterManager?
	}
}

The documentation should contain all you need to know about this one. It’s a pretty common problem and I’m also certain you can find the answer here on UA. But anyways, what you could do is move your enemy transform towards your player transform. After you’ve found the gameobject, which is your character, you can access the players transform.

public float speed;

void Update() 
{
        float step = speed * Time.deltaTime;
        transform.position = Vector3.MoveTowards(transform.position, playerCharacterManager.transform.position, step);
}

I could just give you some code… but that’s not really going to help you in the long run. You know the saying “give a man a fish, and you feed him for a day, teach a man to fish and you feed him for his whole life?”

You need to understand Vector Math.

Thankfully the Unity Tutorials has a video on Vector Maths…

So go watch this.

http://unity3d.com/learn/tutorials/modules/beginner/scripting/vector-maths-dot-cross-products