I am trying to learn how to use Godot, as I find it easier to learn than Unity, and have been following a tutorial on their official documentation page, I've managed to get to the
'Preparing for Collisions' section, and have created the Hit
signal, however, when I linked the nodes together, it created the function, and I wrote the code it said to put into it:
public void OnPlayerBodyEntered(PhysicsBody2D body)
{
Hide(); // Player disappears after being hit.
EmitSignal("Hit");
GetNode<CollisionShape2D>("CollisionShape2D").SetDeferred("disabled", true);
}
But when I run it and it gives this error:
Feature 'top-level statements' is not available in C# 7.3. Please use language version 9.0 or greater.
I assumed this meant I have to update C#, which I didn't think would be that much of an issue, I tried updating it through the dotnet-sdk
thing, but I'm not really sure what it is or how it works, and cannot find any other way of updating it in Godot. I apologise if this is a stupid question, I'm very new to Godot. Thanks in advance for any help.
CodePudding user response:
I am not entirely sure if that's the snippet of code which produces the top-level statement error. Top-level statement errors usually come from, typically Program.cs
, or the code file that contains the Main
method.
Top-level statements were introduced with C# 9: MSDN - Top-level statements
In order to enable C# 9.0 in your project, you need to edit your .csproj
file and add the following:
<PropertyGroup>
<LangVersion>9.0</LangVersion>
</PropertyGroup>
Alternatively, you can use the following configuration to target the latest C# version, currently 10.0:
<PropertyGroup>
<LangVersion>latest</LangVersion>
</PropertyGroup>