Unity - 启动方法不是 运行

Unity - Start Method not running

我是 Unity 的新手,我正在学习 flappy bird 教程以更加熟悉游戏引擎。我正在关注 CodeMonkey 教程。我在游戏结束屏幕上。这是我附加到我的 GameOverWindow 的脚本。但只有 Awake() 被调用。开始没有。因此,我的活动无法进行,所以游戏结束 window 不会显示。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using CodeMonkey.Utils;

public class GameOverWindow : MonoBehaviour
{
    private Text scoreText;
    // Start is called before the first frame update
    private void Start()
    {
        Bird.GetInstance().OnDied += Bird_OnDied;
    }

    private void Awake()
    {
        scoreText = transform.Find("scoreText").GetComponent<Text>();

        transform.Find("retryBtn").GetComponent<Button_UI>().ClickFunc = () => { UnityEngine.SceneManagement.SceneManager.LoadScene("GameScene"); };
        Hide();
    }

    private void Bird_OnDied(object sender, System.EventArgs e)
    {
        scoreText.text = Level.GetInstance().GetPipesPassedCount().ToString();
        Show();
    }

    // Update is called once per frame
   private void Update()
    {

    }

    private void Hide()
    {
        gameObject.SetActive(false);
    }
    private void Show()
    {
        gameObject.SetActive(true);
    }
}

根据Unity docs

Start is called exactly once in the lifetime of the script. However, Awake is called when the script object is initialised, regardless of whether or not the script is enabled. Start may not be called on the same frame as Awake if the script is not enabled at initialisation time.

所以如果GameOverWindow一开始就被禁用,Start不会被执行,但是Awake会。您可以将事件初始化移动到 Awake 并且它应该可以工作(只要它是添加事件的问题,而不是事件中的代码)。