UnityEngine.dll中的System.Runtime.InteropServices.SEHException

时间:2015-04-14 08:43:48

标签: c# windows visual-studio windows-phone-8 unity3d

我正在为windows phone 8导入unity3D项目,并添加几行代码,将c#代码交互到unity3D中Object(SphereScript)的事件更改处理程序。

var sphereScript = UnityEngine.Object.FindObjectOfType<SphereScript>();
sphereScript.SphereStateChanged += sphereScript_SphereStateChanged;
sphereScript_SphereStateChanged(sphereScript.IsSphereMoving);

该项目编译良好,没有错误,但当它在手机上运行时,它会在行上出错

UnityEngine.Object.FindObjectOfType<SphereScript>();

UnityEngine.DLL中出现'System.Runtime.InteropServices.SEHException'类型的异常,但未在用户代码中处理。我不知道为什么会出现这种错误。但是当我第一次启动项目时,它要求我找到文件名 UnityEngineObject.cs 。我在哪里可以找到这个文件或如何解决问题。感谢。

完整代码http://docs.unity3d.com/Manual/wp8-unity-interaction.html

的网址

1 个答案:

答案 0 :(得分:0)

在Unity 5x中,我有同样的问题。 所以试试这个:

在脚本SphereScript.cs中:

重写:

public event Action<bool> SphereStateChanged;

到此:

public static event  Action<bool> SphereStateChanged = delegate { };

接下来,在构建项目后的Visual Studio中取消注释这些代码部分:

UnityApp.SetLoadedCallback(() => { Dispatcher.BeginInvoke(Unity_Loaded); });

private void Unity_Loaded() { }

现在插入 private void Unity_Loaded()这个:

ShareScript.SphereStateChanged += SphereStateChanged;

最后添加:

void SphereStateChanged(bool currentSpehreState)
{
    Dispatcher.BeginInvoke(() =>
    {
        SphereStateTextBlock.Text = currentSpehreState ? "Spehre is moving" : "Sphere is stopped";
    });
}
祝你好运,再见:)