how to check button click in between running function ?

One of my function is running and I have to detect button click in between, then how do i check button click ?

  1. Either stop function on half way until button click.
  2. Or have to detect button click as fast as possible.

Considering first option, Can I stop any function half way and re-run (From where function stopped) after button click ?

Note: Function is normal function not Update or Start.

What you want is a coroutine. Unity - Manual: Coroutines

Something like this:

public class FuncWaitingForButtonClick : MonoBehaviour
	{
		public bool buttonWasClicked;

		public void Start()
		{
			StartCoroutine(Function());
		}

		private IEnumerator Function()
		{
			// Do stuff before click

			while (!buttonWasClicked)
			{ // this loop will return as long as the bool is false
				yield return null;
			}

			// Do stuff after click
		}
	}