如何解决我正在尝试在Spark AR中为我的游戏提供计分功能,但是promise.all似乎不起作用
我对编程非常陌生,我试图使用脚本来修补桥接技术。我不知道为什么这不起作用,这是我的代码:
const Scene = require('Scene');
const Patches = require('Patches');
export const Diagnostics = require('Diagnostics');
const patchValue = Patches.getScalarValue('Gamescore');
Promise.all([
Scene.root.findFirst("sampletxt"),]).then(function(results){
var scoreText = results[0];
scoreText.text = patchValue.toString();
});
Diagnostics.watch('runtime -',patchValue); // im using this line to see if the script reads the value from patch.
这是控制台日志中的错误:
改为使用PatchesModule.outputs.getScalar
!
@
HermesRuntime
不建议使用此API,请升级到最新的SDK版本。讯息:
@
HermesRuntime
Possible Unhandled Promise Rejection: Unexpeted SceneObject reference: {"identifier":"2_d_text_model:7030-1be1a0e4-3bb6-4a3b-bc9c-e17b7b57aa6c","name":"sampletxt","materialIdentifier":"","className":"planarText","modelId":505}
请帮助我,谢谢
解决方法
- GameScore从修补程序接收一个数字值,并将其发送到脚本。
- ScoreText从GameScore获取值并保留它。
- outputScore从ScoreText中获取值,并将其发送回补丁。
- 然后在补丁中,将outputScore补丁连接到sampletxt的文本补丁。
const Patches = require("Patches");
//onStart Set GameScore Value
Patches.outputs.getScalar("GameScore").then((event) => {
var ScoreText = event.pinLastValue();
Patches.inputs.setString("outputScore",ScoreText.toString());
//onChange Update GameScore Value
event.monitor().subscribe(function (values) {
ScoreText = values.newValue;
Patches.inputs.setString("outputScore",ScoreText.toString());
});
});
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。