相关疑难解决方法(0)

Unity Visual Studio C#版本同步

我刚开始在我的Unity游戏中使用委托和事件来在适当的时候更新标签,而不是每帧更新标签,尽管大多数时候没有发生变化.

为了确保,这是一个静态事件调用

public static event OnSomething onSomething;
Run Code Online (Sandbox Code Playgroud)

实际上有听众,我用

if (onSomething!= null) {
    onSomething();
}
Run Code Online (Sandbox Code Playgroud)

这只是一个方便的问题,但Visual Studio 14(2015)说,这可以简化为

onSomething?.Invoke();
Run Code Online (Sandbox Code Playgroud)

我也更喜欢,因为我熟悉nullables并想使用它们,但如果我确实将代码更改为建议,Unity表示

error CS1644: Feature `null propagating operator' cannot be used, because it is not part of the C# 4.0 language specification.
Run Code Online (Sandbox Code Playgroud)

那么有没有办法让Unity项目使用C#的v4.0,或者我可以告诉Visual Studio,该项目使用旧版本的C#,所以它会停止这些建议吗?

编辑:很少澄清:我不一定要使用任何特定的C#版本.我想使用最新版本来使用这些"酷炫的新功能",只要没有主要原因不使用最新版本.

c# unity-game-engine visual-studio

5
推荐指数
1
解决办法
5924
查看次数

标签 统计

c# ×1

unity-game-engine ×1

visual-studio ×1