I just started to use delegates and events in my Unity game to update labels when appropriate, instead of updating the labels every frame, although most of the time no changes occur.
To make sure, that a static event call of
public static event OnSomething onSomething;
actually has listeners, I use
if (onSomething!= null) {
onSomething();
}
It's just a convenience problem, but Visual Studio 14 (2015) says, that this can be simplified to
onSomething?.Invoke();
which I also like more, because I'm familiar with nullables and would like to use them, but if I do change the code to the suggestion, Unity says
error CS1644: Feature `null propagating operator' cannot be used, because it is not part of the C# 4.0 language specification.
So is there a way to make a Unity project use v4.0 of C#, or can I tell Visual Studio, that the project uses an older version of C#, so it stops these suggestions?
Edit: Little clarification: I don't neccessarily want to use any specific C# version. I want to use the newest version possible to use these "cool new features", as long as there is no major reason not to use the newest version.