【问题标题】:Unity SetActive() doesn't activate objectUnity SetActive() 不激活对象
【发布时间】:2018-11-20 21:03:14
【问题描述】:

我有一个自己无法解决的问题。

我有一个暂停按钮,需要在场景中激活暂停面板,但没有任何效果。 1.我在检查器中附加了一个公共GO“面板”。 2.Inspector 写道:“没有‘GameObject’附加到‘Panel’游戏对象,但有一个脚本正在尝试访问它。” 3. 始终激活 GO 上的脚本。 4.开始时面板处于活动状态。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;

public class ButtonController : MonoBehaviour {

    private Scene ActiveScene;
    private GameController gm;
    public GameObject panel;
    // Use this for initialization
    void Start ()
    {
    gm = GetComponent<GameController>();
    ActiveScene = SceneManager.GetActiveScene();
        panel.SetActive(false);

    }

    public void Pause()
    {
        Debug.Log("Pause");
        panel.SetActive(true);
        Time.timeScale = 0;
    }

    public void Menu()
    {
        SceneManager.LoadScene(0);
    }

    public void Restart()
    {
        SceneManager.LoadScene(ActiveScene.buildIndex);
    }

    public void Play()
    {
            Time.timeScale = 1;
            panel.SetActive(false);
    }

很高兴你能帮忙!

【问题讨论】:

  • 在 Stack Exchange 的游戏开发中做这个问题。
  • 谢谢,完成!
  • @AAShakil:请不要因为任何关于 Unity 的问题而重定向游戏开发人员。如果他们是关于编程的,在这里询问是绝对合法的。
  • @Andreaジーティーオー 我试图帮助他获得更好的答案。
  • @AAShakil GameDev SE 实际上比 SO 上的 [unity3d] 标签的流量。此外,不鼓励在 Game Dev 和 SO 上交叉发布问题。

标签: c# unity3d game-development


【解决方案1】:

我解决了这个问题:我附加了两次脚本。

【讨论】:

    猜你喜欢
    • 2021-03-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    相关资源
    最近更新 更多