diff --git a/tutorials/scripting/instancing_with_signals.rst b/tutorials/scripting/instancing_with_signals.rst index c28f1d01fab..40054f2d684 100644 --- a/tutorials/scripting/instancing_with_signals.rst +++ b/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("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(); + 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