how do i stop/exit a coroutine?

how can i stop or exit function while its working?
my code is below

function ChangeColor(){
   timer = 0;
   RandomNumber=Random.Range(5,9);
   yield WaitForSeconds(RandomNumber);
   renderer.material.SetTexture("_MainTex", yellow);
   cc=1;
}

i want to stop this function or change “waitforseconds” time while the program waiting for “randomnumber”.
for some reason, i just wanna let it finish running this function as soon as possible.

any help would be appreciated

The namepace will auto resolve in most IDEs but it wont contain .dll it will probably be something like using Newtonsoft.Json;

1 Answer

1

This is not exactly a function, it’s a coroutine. To exit them while they are being run you can use MonoBehaviour.StopCoroutine();