How to move object, then stop, then resume with button

Hi, first of all id like to say im pretty new to coding. Im a graduate in Animation and got into game development.

The Case:

I have a Mammoth moving from left to right, and i want it to stop halve way. Then by pressing one of the new OnClick GUI buttons i want him to resume moving until hes out of the picture. (he would move right until he falls into the abyss.

I was able to make him stop with a transform.position.x >= 0 but then i couldnt make him move again by calling ResumeWalk with Onclick button. Also when he stops his animation will go on for 2 seconds before transitioning to AnimState 1 wich is Idle Animation.

Help plz.

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Move_forward_stop : MonoBehaviour {

	private bool dirRight = true;
	public float speed = 1.0f;
	private Animator animator;

	// Use this for initialization
	void Start () {
		animator = GetComponent<Animator> ();
	}
		public void ResumeWalk () {
			speed = 1.0f;
			
		}

	
	// Update is called once per frame
		void Update () {
			if (dirRight)
				transform.Translate (Vector2.right * speed * Time.deltaTime);
	

			if(transform.position.x >= 0) {
				speed = 0f;
				animator.SetInteger ("AnimState", 1);
			}
			
			
}

The problem is regardless you clicked the button or not, the position of the gameObject remain greater or equal to 0 and so speed will still be 0. The moment you clicked, speed might’ve turn to 1 and during the same frame, Update already reset it to 0.

Rather then making the condition base on position, you can do the following:

public bool halfway;
public bool firstTime = false;

...

void Update(){

...

if(!firstTime){
 if(transform.position.x >= 0){

 firstTime = true;
 halfway = true;

 }
}

if(halfway){
speed = 0f;
} else {
speed = 1f;
}

}

public void ResumeWalk(){
halfway = false;
}

Ok now he is doing what i want. Thanks for that, the only issue i have right now is that he starts walking as soon as the scene starts. How can i make a button so that he is stationary until i press it? or even better use the same button but the 1st press is to make him walk and the second to resume once he is stationary.

My code atm:

using UnityEngine;
using System.Collections;

public class Move_forward_stop_final : MonoBehaviour {

	public bool halfway = false;
	public bool firstTime = false;
	public float speed = 1.0f;
	private Animator animator;


	// Use this for initialization
	void Start () {
		animator = GetComponent<Animator> ();

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




		if(!firstTime){
			if(transform.position.x >= 0){
				firstTime = true;
				halfway = true;
				
			}
		}
		
		if(halfway){
			animator.SetInteger ("AnimState", 1);
			speed = 0f;

		} else {
			animator.SetInteger ("AnimState", 2);
			transform.Translate (Vector2.right * speed * Time.deltaTime);
			speed = 1f;
		}
		
	}
	
	public void ResumeWalk(){
		halfway = false;
	}
	}