Scripting enemy path in 2D platformer.

I have coded it so that the enemy turns around when it hits the WallLeft, but for some reason it won’t turn around when it hits WallRight.
This .GIF shows the situation.

    using UnityEngine;

/// <summary>
/// Simply moves the current game object
/// </summary>
public class MoveScript : MonoBehaviour
{
	// 1 - Designer variables
	
	/// <summary>
	/// Object speed
	/// </summary>
	public Vector2 speed = new Vector2(5, 5);
	bool touchingWallLeft = false;
	bool touchingWallRight = false;
	public Transform wallCheckLeft;
	public Transform wallCheckRight;
	float wallTouchRadius = 0.5f;
	public LayerMask whatIsWallLeft;
	public LayerMask whatIsWallRight;
	
	/// <summary>
	/// Moving direction
	/// </summary>
	public Vector2 direction = new Vector2(-1, 0);
	
	public Vector2 movement;
	
	void Update()
	{

	}
	
	void FixedUpdate()
	{
		// 2 - Movement
		movement = new Vector2(
			speed.x * direction.x,
			speed.y * direction.y);

		// Apply movement to the rigidbody
		rigidbody2D.velocity = movement;

		touchingWallLeft = Physics2D.OverlapCircle(wallCheckLeft.position, wallTouchRadius, whatIsWallLeft);
		touchingWallRight = Physics2D.OverlapCircle(wallCheckRight.position, wallTouchRadius, whatIsWallRight);

		if (touchingWallLeft)
		{



				speed.x = -5;
				direction.x = -1;
			
			
			// 2 - Movement

	}
		else if (touchingWallRight) {
			


				speed.x = 5;
				direction.x = 1;
			
						
			 
				}
}

}

You are multiplying -5 by -1 when he’s touching WallLeft (when he needs to start moving right), and then multiplying 5 by 1 when he is touching WallRight (when he needs to start moving left).

-5 * -1 = 5 * 1 = 5. The negatives in -5 * -1 cancel, thus giving the same number as 5 * 1. Both result in him moving the same direction. You shouldn’t change speed out, you should swap direction when the event occurs.

In stead, you should only change direction’s value.

When he should move right, make direction.x 1.

When he should move left, make direction.x -1.

Speed should never have to change.