有没有办法从另一个脚本访问异步函数内的函数?

Is there a way to access a function that is inside an async function from another script?

在 spark AR 中,我有多个脚本:一个 UIManager 脚本和一个 GameManager 脚本。我的 UI 管理器中的异步函数内有一个游戏结束函数,但我想通过 GameManager 访问该函数。

我试过在游戏结束前设置导出功能,但这是不允许的,而且我在网上找不到任何东西。有人知道这样做的方法吗?

代码:

(async function() 
{

//Function that gets called when the game is lost
export function GameOver(score = 0)
{
    //Make the Game over screen visible
    LoseScreen.hidden = false;

    //Check if the gme has a shop
    if(GameSettings.RequireShop)
    {
        //Make the Shop button visible
        ShopButton.hidden = false;
    }
    else if(!GameSettings.RequireShop)
    {
        //Make the Shop button invisible
        ShopButton.hidden = true;
    }
    
    //Set the value to the current screen
    CurrentScreen = "LoseScreen";

    //Make the game invisible
    //NOTE: end the game here when making the final game
    GameMenuObj.hidden = true;

    //Score variable saved here and displayed on screen
    Score = score;
    TotalScore += Score;

    LoseScore.text = Score.toString();

    //Check if the game has a Leaderboard or shop
    if(GameSettings.RequireleaderBoard || GameSettings.RequireShop)
    {
        //save your new score and money
        SaveData();
    }
    
    //show / refresh money on screen
    CoinText.text = TotalScore + "";
}

//Enables async/await in JS [part 2]
})();
(async function() {
  // ...
  function GameOver(score = 0) {
    // ...
  }
})

变成

/* ... all the variables and functions declared inside the async function
 * to whom the GameOver needs access should now be passed as arguments
 */
export function GameOver(
  /* ... arguments from the async function */,
  score = 0
) {
  // ...
}

(async function() {
  // ...
  GameOver(/* ... arguments */)
})