Unity SetActive()不会激活对象

时间:2018-06-11 14:56:28

标签: c# unity3d unityscript stackexchange.redis game-development

我遇到了一个我自己无法解决的问题。

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

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);
    }

如果你能提供帮助,我很高兴!

1 个答案:

答案 0 :(得分:0)

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