Enemy wont move in the correct direction.

Hi I was having some problem with my enemy Ai code where the enemy would turn a random direction. Now because I do not want to turn the actual object and just want it to move in that angle I having a litte difficulty with the math. Here is the code:

if( counter <= 0)

{

        counter = 1;
		dir = Mathf.Deg2Rad*Random.Range(0,360);

	}
	else
		counter -= Time.deltaTime;
	//moves the object in the x and z direction
	amountToMove.x = Mathf.Sin(dir)*spd*Time.deltaTime;
	amountToMove.z = Mathf.Cos(dir)*spd*Time.deltaTime;

Now part of the reason that I’m having difficulty is because I am not sure what direction the object should be moving so it is hard to tell if it is actually moving in the right direction.

To rotate your gameobject towards a target, Use Vector3.RotateTowards()

To move your gameobject towards a target, Use MathF.Movetowards()

Seems tricky. From this code it is going to be changing directions very quickly, every second. How is the object currently moving/ why do you suspect it is not moving correctly?

If I were approaching this problem blank I would probably give the object a directional Vector3 or Vector2 depending on what is needed. This vector would be used to define the current heading of the object and could then be used to translate the object by way of multiplying a speed and time variable.