Advertisement
Guest User

Godot 2d c# Slot

a guest
May 26th, 2022
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.97 KB | None | 0 0
  1. using Godot;
  2. using System;
  3.  
  4. public class Slot : Control
  5. {
  6.   private bool isDragged = false;
  7.  
  8.   // Called when the node enters the scene tree for the first time.
  9.   public override void _Ready()
  10.   {
  11.  
  12.   }
  13.  
  14.   // Called every frame. 'delta' is the elapsed time since the previous frame.
  15.   public override void _PhysicsProcess(float delta)
  16.   {
  17.     if (isDragged)
  18.     {
  19.       RectGlobalPosition = GetGlobalMousePosition();
  20.     }
  21.   }
  22.  
  23.   private void _on_Slot_gui_input(InputEvent @event)
  24.   {
  25.     if (@event is InputEventMouseButton mouseButton)
  26.     {
  27.       if (mouseButton.ButtonIndex == (int)ButtonList.Left)
  28.       {
  29.         if (mouseButton.Pressed)
  30.         {
  31.           isDragged = true;
  32.         }
  33.         else
  34.         {
  35.  
  36.           isDragged = false;
  37.         }
  38.       }
  39.       else if (mouseButton.ButtonIndex == (int)ButtonList.Right && mouseButton.Pressed)
  40.       {
  41.         GetTree().Root.GetNode<Player>("Node2D/Player").RemoveItem(this);
  42.       }
  43.     }
  44.   }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement