小编ali*_*rek的帖子

Unity3D 错误 CS0229 - 变量之间的错误歧义

我在使用 Unity(版本 2020.3.5f1 LTS)时遇到问题。特别是,我将一个项目从一台计算机移至另一台计算机,并且多次出现此错误:

错误 CS0229 “TimeCounter.singleton”和“TimeCounter.singleton”之间存在歧义

我知道当你有两个同名的不同变量时会发生这种错误,因为编译器无法区分它们;不过,我没有这种特殊情况。事实上,TimeCounter我的项目中只有一个类,并且没有重复的变量名称。

我尝试通过删除 .sln 项目并通过 Unity 重新创建它(如此处的建议来解决此问题,但它不起作用。

产生错误的类如下:

using System.Collections;
using UnityEngine;
using EventSystem2;

public class TimeCounter : MonoBehaviour
{
    [SerializeField] float minutesToPlay = 2f;
    float currentTime = 0f;

    public GameEvent endedTimeEvent;

    private static TimeCounter singleton;

    void Awake()
    {
        if (!singleton)
        {
            singleton = this;
            DontDestroyOnLoad(this);
        }
    }

    void Start()
    {
        currentTime = minutesToPlay * 60f;
    }

    IEnumerator Timer()
    {
        while (true)
        {
            if (currentTime > 0f)
            {
                currentTime -= …
Run Code Online (Sandbox Code Playgroud)

c# unity-game-engine

3
推荐指数
1
解决办法
1070
查看次数

标签 统计

c# ×1

unity-game-engine ×1