Flipping an enemy sprite and stop

the enemy sprite wont flip when it changes direction in a 2D environment, i tried using this first code. the monodelvelopment editor says it doesn’t know what flip is.
i got the code from a character controller, but my question is am i useing it totally wrong? O_o

    void FixedUpdate (){
float move = Input.GetAxis ("Horizontal");
    		rigidbody2D.velocity = new Vector2 (move * maxSpeed, rigidbody2D.velocity.y);
    	if (move > 0 && ! facingRight)
    						Flip ();
    				else if (move < 0 && facingRight)
    						Flip ();
    void Flip()
    	{
    		facingRight = !facingRight;
    		Vector3 theScale = transform.localScale;
    		theScale.x *= -1;
    		transform.localScale = theScale;
    		}

also I need the enemy ai to make the enemy stop when it gets to the player, or at a distance of something like 2. i have the “agro” side done. any tips on where to go? its a 2D platformer.

using UnityEngine;
using System.Collections;

public class EnemyAI : MonoBehaviour {
	public Transform target;
	public int moveSpeed;
	public int maxDistance;
	public int rotationSpeed;
	public Transform myTransform;
	bool facingRight = true;

	void Awake() {
		myTransform = transform;
	}  
	
	// Use this for initialization
	void Start () {

		GameObject go = GameObject.FindGameObjectWithTag("Player");
		
		target = go.transform;
		
		maxDistance = 15;
	}   
	
	void update (){
				
				
			}
		

		void FixedUpdate () {
			if (Vector3.Distance (target.position, myTransform.position) < maxDistance) {
						if (target.position.x < myTransform.position.x)
								myTransform.position -= myTransform.right * moveSpeed * Time.deltaTime; // player is left of enemy, move left
			else if (target.position.x > myTransform.position.x)
								myTransform.position += myTransform.right * moveSpeed * Time.deltaTime; // player is right of enemy, move right

		}
		Debug.DrawLine(target.position, myTransform.position, Color.yellow);
	




	
	}

}

Is your first block of code copied directly out of your editor? Are you missing a bracket closing FixedUpdate()? Because to me it looks like you’ve placed Flip() inside FixedUpdate(), but maybe I’m missing some of the code.

For your second issue, you should have another check inside your first distance check. Same thing, but if the distance is greater than whatever you want the offset to be, don’t update the position. Pseudo code example.

float distance = Vector.Distance();
if((distance < maxDistance) && (distance > minDistance))
{
    // Update movement        
}