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:
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;
DoAThing();
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.
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.