Godot Version
4.2.2 Godot.NET
Question
I am working on a basic main menu and I wanted to try and turn my GDScript into C#.
The code for C# is as follows:
This code doesn’t work
using Godot;
public partial class NewMainMenu : Node
{
private void _on_level_1_play_pressed()
{
GetTree().ChangeScene("res://scene/level1.tscn");
}
private void _on_level_2_play_pressed()
{
GetTree().ChangeScene("res://scene/level2.tscn");
}
private void _on_level_3_play_pressed()
{
GetTree().ChangeScene("res://scene/level3.tscn");
}
}
The errors I am getting are as follows
CS1061: ‘SceneTree’ does not contain a definition for ‘ChangeScene’ and no accessible extension method ‘ChangeScene’ accepting a first argument of type ‘SceneTree’ could be found (are you missing a using directive or an assembly reference?) /Users/username/Godot_Projects/scene/newMainMenu.cs(7,13)
CS1061: ‘SceneTree’ does not contain a definition for ‘ChangeScene’ and no accessible extension method ‘ChangeScene’ accepting a first argument of type ‘SceneTree’ could be found (are you missing a using directive or an assembly reference?) /Users/username/Godot_Projects/scene/newMainMenu.cs(12,13)
The GDScript I am using that worked was:
extends Node
func _on_button_pressed():
get_tree().change_scene_to_file("res://scene/level1.tscn")
func _on_button_2_pressed():
get_tree().change_scene_to_file("res://scene/level2.tscn")
Is there something I have done wrong? How do I get the C# code to work