[Unity] GameObject에서 StartCoroutine 사용하기

pangcola(34)
Published in
#unity
Words
0
Reading
0 min
9y
Listen to this post
~1 min
  public static Coroutine StartCoroutine(this GameObject go, IEnumerator routine)
  {
      MonoBehaviour mono = go.GetComponent<MonoBehaviour>();
      if (null == mono)
          mono = go.AddComponent<MonoBehaviour>();

      return mono.StartCoroutine(routine);
  }

  public static void StopCoroutines(this GameObject go, IEnumerator routine)
  {
      MonoBehaviour mono = go.GetComponent<MonoBehaviour>();
      if (null == mono)
          mono = go.AddComponent<MonoBehaviour>();

      mono.StopCoroutine(routine);
  }

  public static void StopCoroutines(this GameObject go, string methodName)
  {
      MonoBehaviour mono = go.GetComponent<MonoBehaviour>();
      if (null == mono)
          mono = go.AddComponent<MonoBehaviour>();

      mono.StopCoroutine(methodName);
  }

  public static void StopAllCoroutines(this GameObject go)
  {
      MonoBehaviour mono = go.GetComponent<MonoBehaviour>();
      if (null == mono)
          mono = go.AddComponent<MonoBehaviour>();

      mono.StopAllCoroutines();
  }
[Unity] GameObject에서 StartCoroutine 사용하기 | Ecency