MonoBehaviour.StopAllCoroutines

Deklarasyon

public void StopAllCoroutines();


Açıklama

Bu davranış üzerinde çalışan tüm korotinleri durdurur.

Bir MonoBehaviour, sıfır veya daha fazla coroutine çalıştırabilir. Oluşturulan coroutine'ler belirli bir süre boyunca çalışabilir. Aşağıdaki komut dosyası örneğinde, iki coroutine oluşturulmuş ve durdurulmadan çalıştırılmıştır. Ancak, StopAllCoroutines her ikisini de durdurmak için kullanılır. Bu işlem, birden fazla coroutine çalıştıran bir komut dosyası üzerinde gerçekleştirilebilir. Hiçbir argüman gerekmez çünkü bir komut dosyası üzerindeki tüm coroutine durdurulur.
Not: StopAllCoroutines yalnızca iliştirildiği tek bir komut dosyası üzerinde çalışır.

using UnityEngine;
using System.Collections;

// Farklı hızlarda çalışan iki coroutine oluşturun.
// Boşluk tuşuna basıldığında her ikisini de durdurun. public class ExampleClass : MonoBehaviour { // coroutine 1
IEnumerator DoSomething1() { while (true) { print("DoSomething1"); yield return new WaitForSeconds(1.0f); } } // coroutine 2 IEnumerator DoSomething2() { while (true) { print("DoSomething2"); yield return new WaitForSeconds(1.5f); } } void Start() { StartCoroutine("DoSomething1"); StartCoroutine("DoSomething2"); } void Update() { if (Input.GetKeyDown("space")) { StopAllCoroutines(); print("Stopped all Coroutines: " + Time.time); } } }

Bu blog Unity Docs'un Türkçeye çevrilmiş halidir.

Yorumlar

Bu blogdaki popüler yayınlar

Important Classes - Vectors

RequireComponent

Important Classes - GameObject