There are several methods in the C # script that are called in turn via InvokeRepeating. (The dog runs, the dog barks) It is necessary that when calling one of these methods (the dog is sleeping), InvokeRepeating is stopped and called the next time manually (when you wake the dog). How to implement it?

    1 answer 1

    InvokeRepeating can be aborted by CancelInvoke

    If you call CancelInvoke() with no parameters, all Invoke calls in this script will be canceled.

    To cancel a specific Invoke - you need to pass the name of the method that should be interrupted.

    For example, the launch was like this:

     InvokeRepeating("RespawnCreatures", 0, 3); 

    and you can cancel it like this:

     CancelInvoke("RespawnCreatures"); 
    • Thank you, I already use this method, the problem is how to start it again. Here is my code. Running does not start again, but needs to be started when you touch the screen void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { ohoho1++; } { void son() { dir = new Vector3(0, 0, -1); myTransform.Translate(dir * 0); CancelInvoke(); if(ohoho1 > 0) { InvokeRepeating("Running", 1, 2); ohoho1 = 0; } void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { ohoho1++; } { void son() { dir = new Vector3(0, 0, -1); myTransform.Translate(dir * 0); CancelInvoke(); if(ohoho1 > 0) { InvokeRepeating("Running", 1, 2); ohoho1 = 0; } void Update() { if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Began) { ohoho1++; } { void son() { dir = new Vector3(0, 0, -1); myTransform.Translate(dir * 0); CancelInvoke(); if(ohoho1 > 0) { InvokeRepeating("Running", 1, 2); ohoho1 = 0; } - Dmitrii am
    • Maybe the fact is that I hang this script? If the script is hanging on the dog, then he also counts the clicks only on the dog? Or does he count click on everything? - Dmitrii am
    • one
      @Dmitrii I have no idea. I'm not an extrasensory. I don’t know what you have there in the whole game for logic, where it’s located, what’s where it’s written, what it controls and what is generally planned .......... When you click, one of the conditions may not work for work, you can check out by writing Debug.Log("Im here"); or you can use debugging, as everyone does it ..... And maybe the error falls out at this time and therefore does not work .......... manually you can simply call Running() ...... - Alexey Shimansky