2
0
Эх сурвалжийг харах

Merge pull request #7651 from raulsntos/dotnet/fix-instancing-with-signals

Max Hilbrunner 2 жил өмнө
parent
commit
c5838a5e64

+ 8 - 8
tutorials/scripting/instancing_with_signals.rst

@@ -41,7 +41,7 @@ given velocity:
 
     public partial class Bullet : Area2D
     {
-        Vector2 Velocity = new Vector2();
+        public Vector2 Velocity { get; set; } = Vector2.Zero;
 
         public override void _PhysicsProcess(double delta)
         {
@@ -111,7 +111,7 @@ Here is the code for the player using signals to emit the bullet:
     public partial class Player : Sprite2D
     {
         [Signal]
-        delegate void ShootEventHandler(PackedScene bullet, Vector2 direction, Vector2 location);
+        public delegate void ShootEventHandler(PackedScene bullet, float direction, Vector2 location);
 
         private PackedScene _bullet = GD.Load<PackedScene>("res://bullet.tscn");
 
@@ -147,13 +147,13 @@ In the main scene, we then connect the player's signal (it will appear in the
 
  .. code-tab:: csharp
 
-    public void OnPlayerShoot(PackedScene bullet, Vector2 direction, Vector2 location)
+    private void OnPlayerShoot(PackedScene bullet, float direction, Vector2 location)
     {
-        var bulletInstance = (Bullet)bullet.Instantiate();
-        AddChild(bulletInstance);
-        bulletInstance.Rotation = direction;
-        bulletInstance.Position = location;
-        bulletInstance.Velocity = bulletInstance.Velocity.Rotated(direction);
+        var spawnedBullet = bullet.Instantiate<Bullet>();
+        AddChild(spawnedBullet);
+        spawnedBullet.Rotation = direction;
+        spawnedBullet.Position = location;
+        spawnedBullet.Velocity = spawnedBullet.Velocity.Rotated(direction);
     }
 
 Now the bullets will maintain their own movement independent of the player's