Sunday, July 13, 2014

Facts About Unity3d Coroutines

         Here are some of important facts of Unity3d Coroutines which might help you,

1. You can only stop Coroutines that are invoked using StartCoroutine with string as a argument.


Example:


StartCoroutine("MethodName") can be stop using StopCoroutine("MethodName"),
Coroutines those are invoked as StartCoroutine(MethodName()) will not be cancelled by StopCoroutine("MethodName").

2. You can invoke other class Coroutine even after it is  marked as Private.

Example:


Class1.cs


using UnityEngine;
using System.Collections;

public class Class1 : MonoBehaviour {


// Use this for initialization

void Start () {
}

// Update is called once per frame
void Update () {
}

private void DemoCoroutine(){

print("Coroutine Invoked!");
}
}


Class2.cs


using UnityEngine;
using System.Collections;

public class Class2 : MonoBehaviour {


        // Reference Assigned in Inspector

public Class1 Class1Instance;

// Use this for initialization

void Start () {
        // You can even use singleton calss to invoke Coroutine defined in different class
Class1Instance.StartCoroutine("DemoCoroutine");
}

// Update is called once per frame
void Update () {
}
}


More about Unity3d Coroutine,

1 comment:

  1. Harrah's Lake Tahoe - MapyRO
    Harrah's Lake Tahoe. Lake 시흥 출장안마 Tahoe, Nevada. 부천 출장안마 Directions. 경기도 출장안마 Map. Harrah's Lake Tahoe. 수원 출장안마 Address: 219 N. Vadona, 경산 출장마사지 NV 89449

    ReplyDelete

Popular Posts