From 108796d8eeeac0a99941f8fbdcd88c1c0f0b2b0a Mon Sep 17 00:00:00 2001 From: Hana <48352564+Piralein@users.noreply.github.com> Date: Wed, 11 Jan 2023 19:29:23 +0100 Subject: [PATCH] update c# code example and remove randomize call --- .../first_2d_game/05.the_main_game_scene.rst | 28 ++++--------------- 1 file changed, 5 insertions(+), 23 deletions(-) diff --git a/getting_started/first_2d_game/05.the_main_game_scene.rst b/getting_started/first_2d_game/05.the_main_game_scene.rst index 1e4e36174..22e30c9e5 100644 --- a/getting_started/first_2d_game/05.the_main_game_scene.rst +++ b/getting_started/first_2d_game/05.the_main_game_scene.rst @@ -87,7 +87,9 @@ to instance. .. code-tab:: csharp - public class Main : Node + using Godot; + + public partial class Main : Node { // Don't forget to rebuild the project so the editor knows about the new export variable. @@ -152,25 +154,7 @@ to instance. }; #endif // MAIN_H - -We also add a call to ``randomize()`` here so that the random number -generator generates different random numbers each time the game is run: - -.. tabs:: - .. code-tab:: gdscript GDScript - - func _ready(): - randomize() - - .. code-tab:: csharp - - public override void _Ready() - { - GD.Randomize(); - } - - .. code-tab:: cpp - + // This code goes in `main.cpp`. #include "main.hpp" @@ -190,7 +174,6 @@ generator generates different random numbers each time the game is run: //_music = get_node("Music"); //_death_sound = get_node("DeathSound"); _random = (godot::Ref)godot::RandomNumberGenerator::_new(); - _random->randomize(); } Click the ``Main`` node and you will see the ``Mob Scene`` property in the Inspector @@ -356,7 +339,7 @@ Note that a new instance must be added to the scene using ``add_child()``. // obviously Mob and PathFollow2D, since they appear later on the line. // Create a new instance of the Mob scene. - var mob = MobScene.Instance(); + var mob = MobScene.Instantiate(); // Choose a random location on Path2D. var mobSpawnLocation = GetNode("MobPath/MobSpawnLocation"); @@ -425,7 +408,6 @@ call to ``_ready()``: .. code-tab:: gdscript GDScript func _ready(): - randomize() new_game() .. code-tab:: csharp