Check if a function is no longer being called?

So I have a function being called and I was wondering if there is a way to check if it’s no longer being called so I can set a bool to false? Here is a part of my script:

void Update (){
		startPos = new Vector3(transform.position.x, startHeight, transform.position.z);
			transform.position = Vector3.MoveTowards (transform.position, (startPos + new Vector3(0, 5, 0)), Time.deltaTime*speed);
			transform.position = Vector3.MoveTowards (transform.position, startPos, Time.deltaTime*speed);
	public void OnPressUp () {
		goUp = true;

I want to check if OnPressUp is no longer being called so I can set the bool goUp to false.

You can set a bool to true in the function, and then in LateUpdate() set it to false, and in Update() you can check if the bool is true or false.

A function that’s not async or a coroutine will always be finished unless the program flow is actually in the function. When you do something like this:

int x = 5;
int y = 10;

Everything in DoAThing will be executed before the int y = 10 line is reached. So it doesn’t make any sense to check if your “OnPressUp” function isn’t being called any more, as it’s not being called anywhere outside itself.

I think I understand what you want.

From the code you shared I guess you are detecting when the “Up” key is pressed and you set that goUp variable to “true”. You keep the button pressed and your object keeps moving up, but when you release the Up key, it keeps going up. So, you want a way to detect when the up key is released, am I right?

If you managed to detect a key being pressed you should be able to do something similar to detect when a key is released. For example, if you used the Input.GetKeyDown method to check if a key was pressed, you can use Input.GetKeyUp to check if it was released. It could be done in different ways, if you share the actual code that detects the key being pressed it would be easier to help you with the release event.

When you detect a release event you have to call a different function that sets goUp to false.

Just to be clear, when you hold a the Up key down the function is not “being called” during the whole time you held it down, it’s called one time that last a few milliseconds. Functions are not “being called”, functions are called and they finish, and can be called again and again.