void gravincrease()
{
Physics.gravity = grav;
grav.y -= 0.05f * Time.deltaTime;
}
I don’t want to write this code in update. Because whenever I want, I want to using CancelInvoke. How can I make such a function permanent?
or how can I stop these codes for a while when I start a coroutine?
I would just make a WaitForSeconds coroutine with no delay and stop the coroutine through a boolean flag.
IEnumerator gravincrease(float delay=0f){//default argument - does not need to be filled
yield return new WaitForSeconds(delay);//wait for delay
Physics.gravity = grav;
grav.y -= 0.05f;
if(!boolFlag)//if your flag is false
StartCoroutine(gravincrease(delay));//call this function again
}
Hoped this helped :).
Also as a side note, it is recommended to comment your code and camelcase (or some other method) to name functions and variables.
You can assign a coroutine to a variable like so:
Coroutine downGravCoroutine = StartCoroutine(downgrav());
You can then stop it later using:
StopCoroutine(downGravCoroutine());