Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Unity-启动方法未运行_C#_.net_Unity3d_Flappy Bird Clone - Fatal编程技术网

C# Unity-启动方法未运行

C# Unity-启动方法未运行,c#,.net,unity3d,flappy-bird-clone,C#,.net,Unity3d,Flappy Bird Clone,我是Unity的新手,我正在学习flappy bird教程,以便更加熟悉游戏引擎。我正在学习CodeMonkey教程。我正在看屏幕上的游戏。这是我附加到GameOverindow的脚本。但是只有Awake()被调用。开始时没有。因此,我的活动不起作用,因此“游戏结束”窗口不会显示 using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using Co

我是Unity的新手,我正在学习flappy bird教程,以便更加熟悉游戏引擎。我正在学习CodeMonkey教程。我正在看屏幕上的游戏。这是我附加到GameOverindow的脚本。但是只有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);
    }
}
使用系统集合;
使用System.Collections.Generic;
使用UnityEngine;
使用UnityEngine.UI;
使用CodeMonkey.Utils;
公共类游戏:单一行为
{
私人文本;
//在第一帧更新之前调用Start
私有void Start()
{
Bird.GetInstance().OnDied+=Bird_OnDied;
}
私人空间
{
scoreText=transform.Find(“scoreText”).GetComponent();
transform.Find(“retryBtn”).GetComponent().ClickFunc=()=>{UnityEngine.SceneManagement.SceneManager.LoadScene(“游戏场景”);};
隐藏();
}
私有无效Bird__________________________________________
{
scoreText.text=Level.GetInstance().GetPipesAssedCount().ToString();
Show();
}
//每帧调用一次更新
私有void更新()
{
}
私有虚隐藏()
{
gameObject.SetActive(false);
}
私人电视节目()
{
gameObject.SetActive(true);
}
}
根据

在脚本的生命周期中只调用一次Start。但是,在初始化脚本对象时,无论脚本是否启用,都会调用唤醒。如果在初始化时未启用脚本,则不能在与唤醒相同的帧上调用Start

因此,如果GameOverWindow从一开始就被禁用,则不会执行Start,而是唤醒。您可以将事件初始化移动到唤醒,它应该可以工作(只要添加事件时出现问题,而不是在事件中编码)。

根据

在脚本的生命周期中只调用一次Start。但是,在初始化脚本对象时,无论脚本是否启用,都会调用唤醒。如果在初始化时未启用脚本,则不能在与唤醒相同的帧上调用Start


因此,如果GameOverWindow从一开始就被禁用,则不会执行Start,而是唤醒。您可以将事件初始化移动到唤醒状态,它应该可以工作(只要添加事件时出现问题,而不是事件中的代码)。

您确定Start()不工作,而不是事件中的代码吗?@Frytek-yes。我使用VisualStudio进行调试,但它从未启动。我把断点放在start()的开头,你确定start()不工作,而不是事件本身的代码吗?@Frytek是的。我使用VisualStudio进行调试,但它从未启动。我将断点放在start()的开头