我是 Unity 的新手,我正在学习一个飞扬的小鸟教程,以更加熟悉游戏引擎。我正在关注 CodeMonkey 教程。我在游戏结束屏幕。这是我附加到我的 GameOverWindow 的脚本。但只有 Awake() 被调用。开始没有。因此,我的活动无法正常工作,因此游戏结束窗口不会显示。
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);
}
}