Spark AR脚本无法将补丁与场景合并



我是Spark AR的初学者,我正在尝试构建一个眨眼计数游戏,当我尝试合并场景和补丁时,我遇到了以下错误。

Property 'text' does not exist on type 'Promise<SceneObjectBase>'.

这是我的代码

const Scene = require('Scene');
const Patches = require('Patches');
// Use export keyword to make a symbol available in scripting debug console
export const Diagnostics = require('Diagnostics');

(async function () {  // Enables async/await in JS [part 1]
// To access scene objects
const [directionalLight] = await Promise.all([
Scene.root.findFirst('directionalLight0')
]);
var textScore = Scene.root.findFirst('score_number');
var patchScore = Patches.outputs.getScalar('ScoreJumps');
// To access class properties
const directionalLightIntensity = directionalLight.intensity;
// To log messages to the console
textScore.text = patchScore.toString();

Diagnostics.log('Console message logged from the script.');
})(); // Enables async/await in JS [part 2]

findFirstPromise,因此需要在其上使用await

const textScore = await Scene.root.findFirst('score_number');

最后,

我能够通过在代码中添加@ts-ignore来解决我的问题,如下所示。

const Scene = require('Scene');
const Patches = require('Patches');
// Use export keyword to make a symbol available in scripting debug console
export const Diagnostics = require('Diagnostics');
// To use variables and functions across files, use export/import keyword
// export const animationDuration = 10;
// Use import keyword to import a symbol from another file
// import { animationDuration } from './script.js'
(async function () {  // Enables async/await in JS [part 1]
// To access scene objects
const [directionalLight] = await Promise.all([
Scene.root.findFirst('directionalLight0')
]);

var countNum = await Scene.root.findFirst('number');
var scoreNumber = (await Patches.outputs.getScalar('score'));
// To access class properties
const directionalLightIntensity = directionalLight.intensity;
// @ts-ignore
countNum.text = scoreNumber.toString();
// @ts-ignore
Diagnostics.log("wererwerwe"+countNum.text);


// To log messages to the console
Diagnostics.log('Console message logged from the script.');
})(); // Enables async/await in JS [part 2]

最新更新