【问题标题】:Why am I getting this error in unity c# and how do i fix it?为什么我在统一 c# 中收到此错误,我该如何解决?
【发布时间】:2021-04-11 17:48:15
【问题描述】:

我正在尝试统一制作暂停菜单,但它说我无法公开功能。为什么我不能?

它说

CS0106 修饰符“public”对此项无效 Assembly-CSharp、Assembly-CSharp.Player C:\Users\Jaspin\CubeGame\Assets\UI\Paused\PauseMenu.cs 47 Active

三个人都有。

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PauseMenu : MonoBehaviour
{
    public GameObject pauseMenuUI;

    public static bool GameIsPaused = false;

    void Start()
    {

        pauseMenuUI.SetActive(false);

    }


    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (GameIsPaused)
            {
                Resume();
            } else
            {
                Pause();
            }
        }

        void Resume()
        {
            pauseMenuUI.SetActive(false);
            Time.timeScale = 1f;
            GameIsPaused = false;
        }

        void Pause()
        {
            pauseMenuUI.SetActive(true);
            Time.timeScale = 0f;
            GameIsPaused = true;
        }

        public void LoadMenu()
        {
            Debug.Log("Loading menu...");
        }

        public void QuitGame()
        {
            Debug.Log("Quiting game...");
        }
    }
}

【问题讨论】:

  • 您的简历(等)是功能,本地要更新。你错过了一个}

标签: c# visual-studio unity3d game-development


【解决方案1】:

您正在使用嵌套函数。 LoadMenuUpdate 中的嵌套函数。嵌套函数不能有可见性修饰符。

您可能错过了第 32 行中的 }

【讨论】:

  • 非常感谢!
猜你喜欢
  • 1970-01-01
  • 2022-01-14
  • 1970-01-01
  • 2020-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-06-29
  • 1970-01-01
相关资源
最近更新 更多