The StopCoroutine method is similar to the StartCoroutine method, with two overloads.
void StopCoroutine(string methodName)
void StopCoroutine(IEnumerator routine)
this method can either pass in the methodName of the coroutine method as a parameter of type string or of type IEnumerator. Next, the StopCoroutine method is used:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class StopCoroutine : MonoBehaviour {
IEnumerator DoSomething(float someParameter)
{
print("DoSomething Loop");
yield return null;
}
IEnumerator Start()
{
StartCoroutine("DoSomething",2.0f);
yield return new WaitForSeconds(1);
StopCoroutine("DoSomething");
}
}
This code opens a coroutine called DoSomething, which, if run continuously, prints out the phrase “DoSomething Loop”. So after waiting a second, the code stops the coroutine when it executes on the StopCoroutine line.
note: this is when the StopCoroutine method is not used
note: this is when the method is used
The StopCoroutine method can only stop the same coroutine in the same game script with the same Chinese name and string parameter passed in, and cannot affect the coroutine opened in other scripts. The StopCoroutine method, meanwhile, can only StopCoroutine that was started with an overloaded version of StartCoroutine’s string argument.
Read More:
- Notes on unity project_ Unity webplayer failed to update unity web player
- Android learning notes 03: some problems and solutions in the learning process
- TypeError: An asyncio.Future, a coroutine or an awaitable is
- Unity-failed to update unity web player
- Redirecting to /bin/systemctl stop firewalled.service Failed to stop firewalled.service: Unit firewa
- OpenGL learning notes and other learning thinking
- Unity install ilruntime plug-in [novice installation tutorial] (supported by unity2018 and later versions)
- Unity3d open prompt failed to initialize unity graphic
- After unity connects with androidstudio, unity packages APK with an error: commandinvocationfailure: failed to re package resources
- 【Unity 3D】Because you are not a member of this project this build will not access Unity services.
- Create game scene in unity_ Creating a beat em up game in unity
- Error analysis of receive comments before first target. Stop
- Stop: job failed while stopping
- MacOS: How to start or stop Docker
- Redirecting to /bin/systemctl stop mysqld.service
- Removing stop words —— Python Data Science CookBook
- Sklearn ValueError: empty vocabulary; perhaps the documents only contain stop words
- The problem of master-slave database synchronization stop caused by MySQL deleting data
- Vs compile VTK, only generate install error, stop, ask God how to solve?
- Windows Realtek USB wireless network card boot failure Rtlihvs. DLL module stop problem