Нажимная плита

This commit is contained in:
Евгений Титаренко 2023-08-18 02:27:48 +03:00
parent aca884b891
commit 2e5d268f35
5 changed files with 108 additions and 4 deletions

View file

@ -0,0 +1,49 @@
using Godot;
using System;
public partial class PressurePlate : Area2D
{
private bool _pressed = false;
private int _onButton = 0;
private AnimatedSprite2D _sprite;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
}
public override void _PhysicsProcess(double delta)
{
if (_pressed)
{
_sprite.Play("pressed");
}
else
{
_sprite.Play("default");
}
}
private void _onPressed(Node2D body)
{
_onButton += 1;
_pressed = true;
}
private void _onUnpressed(Node2D body)
{
_onButton -= 1;
if (_onButton > 0)
return;
_pressed = false;
}
}