我一直在尝试通过我的 Android 应用程序使用我的 Unity C# 脚本进行通信 "UnityPlayer.UnitySendMessage("Cube", "Test","HELLO") - 其中“Cube”是我的 Unity 对象,“Test”是它正在使用的 C# 脚本中存在的方法的名称,“HELLO”是我要传递的消息字符串。
这一行放在我的 onClick 函数中,像这样:
ImageButton right_button = (ImageButton) findViewById(R.id.right_arrow);
right_button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
UnityPlayer.UnitySendMessage("Cube", "Test","HELLO");
}
});
但是当我运行我的 android 应用程序并单击此按钮时,我收到此错误:
09-11 14:22:37.526: E/AndroidRuntime(1330): java.lang.NoClassDefFoundError: com.unity3d.player.UnityPlayer
我还在构建路径中包含了 classes.jar。 我还遗漏了什么吗?
提前致谢!
最佳答案
检查 class.jar 文件是否在您项目的构建路径中。如果是,检查它是否被选中(复选框被标记)。
Tip: if you get ClassDefNotFound runtime errors (or similar), you might need to perform this extra step:
go to Project > Properties > Java Build Path -> Order and Export tab and check (tick) the classes.jar, Android x.y and Android Dependencies items; then Apply and rebuild the probject.
关于c# - 从 Android 调用 C# Unity 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18744642/