本文介绍了引用Unity3D中的许多协程之一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Unity3D中,是否有一种方法可以将可变点指向C#中的许多协程之一?
Is there a way to have a variable point to one of a number of coroutines in C# in Unity3D?
public class Example : MonoBehaviour
{
? something ? crt;
private IEnumerator CoroutineA()
{
}
private IEnumerator CoroutineB()
{
}
void Start()
{
crt = CoroutineA;
StartCoroutine(crt);
}
}
推荐答案
您要查找的类型是委托.委托类似于函数指针,并且不特定于Unity3D.
The type that you are looking for is a delegate. Delegates are similar to function pointers, and are not specific to Unity3D.
public class Example : MonoBehaviour
{
private delegate IEnumerator CoroutineDelegate();
private IEnumerator CoroutineA()
{
}
private IEnumerator CoroutineB()
{
}
public void Start()
{
CoroutineDelegate crt = CoroutineA;
StartCoroutine(crt());
}
}
这篇关于引用Unity3D中的许多协程之一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!