Stop coroutine

Hey, I would like to count from 10 to 1 and stop if a button is pressed. It counts correctly, but doesn’t stop if the button is pressed. Could you help me?

I tried to write a simmiliar code to this:

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

public class countscript : MonoBehaviour {

	public Text instruction;

	// Use this for initialization
	void Start () {
		instruction = GetComponentInChildren<Text> ();	
		StartCoroutine(Wait10seconds(1.0f));
	}
	
	// Update is called once per frame
	void Update () {
		if (Input.GetButton ("Fire1")) {

			StopCoroutine("Wait10seconds");
		}
	}


	IEnumerator Wait10seconds(float waitTime) {


				while (true) {

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "10";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "9";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "8";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "7";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "6";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "5";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "4";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "3";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "2";

						yield return new WaitForSeconds (1.0f);
						print ("WaitAndPrint " + Time.time);
						instruction.text = "1";
				}
		}
}

Read that documentation page again, and look at the example:

“Please note that only StartCoroutine using a string method name can be stopped using StopCoroutine.”

So your

StartCoroutine(Wait10seconds(1.0f));

Needs to be

StartCoroutine("Wait10seconds", 1.0F);