-1

我正在尝试使用 Unity3D 制作智能手机应用程序,并且正在使用 unityscript。我从 Prime31 购买了一些插件,它们都可以正常工作,但是示例脚本是用 C# 编写的。

我想将下面的示例转换为 JS:

var buttons = new string[] { "Save", "Cancel" };
EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", buttons );

我试过这样:

var buttons:String[];
buttons=["Save","Cancel"];
EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", buttons );

这不好,当然["Save","Cancel"]是在第一个按钮中显示,而在另一个按钮中什么也没有?

我究竟做错了什么?

4

5 回答 5

1

你有任何文件showAlertWithTitleMessageAndButtons()吗?

也许在 JavaScript 中参数是不同的。例如,按钮标题可能作为单独的参数而不是数组传递:

showAlertWithTitleMessageAndButtons("Alert", "Something", "buttonTitle1", "buttontTitle2")

于 2012-07-31T14:54:40.683 回答
1

离开您提供的文档:

 // Shows a standard Apple alert with the given title, message and an array of buttons. At least one button must be included. 
 public static void showAlertWithTitleMessageAndButtons( string title, string message, string[] buttons )

你应该能够使用:

EtceteraBinding.showAlertWithTitleMessageAndButtons( "Alert!", "Do you want to save?", ["Save", "Cancel"]);
于 2012-07-31T15:35:29.797 回答
0

试试这个,我有 Prime31 插件,这对我来说编译得很好。

var test : String[] = ["One", "Two"];
EtceteraBinding.showAlertWithTitleMessageAndButtons("Name","Stuff", test);

如果它不起作用,你在 Unity 中遇到了什么错误?

于 2012-08-22T01:07:45.570 回答
-2

尝试这个:

var buttons = new Array();
buttons.push("Save");
buttons.push("Cancel");
于 2012-07-31T14:56:20.020 回答
-2

那这个呢:

var buttons = new Array("Save","Cancel");
于 2012-07-31T14:52:53.430 回答