Unity多个Coroutines null引用异常

时间:2018-06-04 09:25:54

标签: unity3d

我在答案中看到了同样的问题,但不幸的是我还没有完全理解如何解决这个问题,因为我得到了一个空的引用异常。

我尝试同时运行2个协同程序。每个都来自不同的基类。它们都是相同的,除了类的名称和激活键(一个是向上箭头,另一个是向下箭头)。

public IEnumerator DetectArrow()
{
    if (Input.GetKey(KeyCode.UpArrow))
    {
        if (PrintMessage == null)
        {
            PrintMessage += SendMessage;
        }
    }
    return null;
}

public void SendMessage()
{
    print("I am B.");
    PrintMessage = null;
}

我尝试在整个运行中(从父类)运行这样的东西:

void Update () 
{
    if (b.PrintMessage != null)
    {
        b.PrintMessage();
    }
    if (a.PrintMessage != null)
    {
        a.PrintMessage();
    }
 }

所以我不太确定如何解决这个问题。谢谢你的帮助。

0 个答案:

没有答案
相关问题