相关疑难解决方法(0)

null合并运算符赋值给self

我目前在Unity中设置了两个脚本来处理一些UI音频.一个是经理,另一个是为特定的UI元素播放声音.我所拥有的简化版本如下:

public class AudioUIManager : MonoBehaviour //Only one of these in the scene
{
    public AudioClip genericUISound; //This is set in the inspector.
}
Run Code Online (Sandbox Code Playgroud)
public class AudioUITextAnimation : MonoBehaviour
{
    [SerializeField]
    private AudioClip specifiedUISound; //This is not set in the inspector
    [SerializeField]
    private AudioUIManager audioUIManager; // I get a reference to this elsewhere

    void Start()
    {
        //Use generic sounds from audio manager if nothing is specified.
        specifiedUISound = specifiedUISound ?? audioUIManager.genericUISound;
        print(specifiedUISound);
    }
}
Run Code Online (Sandbox Code Playgroud)

我在这里想要实现的是让该specifiedUISound字段使用在检查器中分配给它的声音.如果未分配声音,则使用UI管理器中的通用声音.这样可以节省我为需要相同声音的数百万个按钮分配相同的声音,但如果我愿意,可以选择为一个按钮设置特定的声音.

然而,在空coalessing算asigning null …

c# null serialization null-coalescing-operator unity-game-engine

6
推荐指数
1
解决办法
557
查看次数

为什么我不能看到API兼容级别的.Net 4.6选项?

我是Unity的新手.我想使用最新版本的.Net.似乎.Net版本最近才升级到.Net 4.6,如本博文中所述:https://forum.unity3d.com/threads/upgraded-mono-net-in-editor-on-5 -5-0b4.433541 /.我没有在博客文章中描述的API兼容级别设置中看到.Net 4.6.我已经尝试使用Unity 5.5.2f1和Unity 5.6.0b9.我可能会失踪什么?

unity-game-engine

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

错误CS1644:无法使用功能“空传播运算符”,因为它不属于C#4.0语言规范

我有Unity 2018.1.9f2,我下载了Unity ml代理并将文件夹添加到我的unity项目中。但是,当我尝试运行“ 3DBall”场景时,在控制台中出现此错误:

资产/ ml-agents-master / UnitySDK /资产/ML-Agents/Scripts/Brain.cs(79,25):错误CS1644:无法使用功能为null的传播运算符,因为它不属于C#4.0语言规范。当我双击它时,它将打开VS并brainBatcher?.SendBrainInfo(name, agentInfos);带有下划线。当我将鼠标悬停在代码上时Feature 'null propagating operator' is not available in C# 4. Please use language version 6 or greater.

我试图遵循另一个类似问题的答案:Unity Visual Studio C#版本同步。因此,我使用unity-c-5.0-and-6.0-integration,但未显示该错误,但出现了150多个其他错误。

任何帮助都感激不尽。

c# unity-game-engine ml-agent

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