Browse Source

Update the outdated "Click-and-move" example in the 2D movement tutorial

Update both the GDScript and C# versions of the "Click-and-move" example in the 2D movement tutorial.
Mateus Elias 1 year ago
parent
commit
4cba7b060e
1 changed files with 8 additions and 4 deletions
  1. 8 4
      tutorials/2d/2d_movement.rst

+ 8 - 4
tutorials/2d/2d_movement.rst

@@ -231,8 +231,9 @@ on the screen will cause the player to move to the target location.
     var target = position
 
     func _input(event):
-        if event.is_action_pressed("click"):
-            target = get_global_mouse_position()
+        if event is InputEventMouseButton:
+            if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
+                target = get_global_mouse_position()
 
     func _physics_process(delta):
         velocity = position.direction_to(target) * speed
@@ -253,9 +254,12 @@ on the screen will cause the player to move to the target location.
 
         public override void _Input(InputEvent @event)
         {
-            if (@event.IsActionPressed("click"))
+            if (@event is InputEventMouseButton eventMouseButton)
             {
-                _target = GetGlobalMousePosition();
+                if (eventMouseButton.ButtonIndex == MouseButton.Left && eventMouseButton.Pressed)
+                {
+                    _target = GetGlobalMousePosition();
+                }
             }
         }