Возможность отключать интерактивные объекты
This commit is contained in:
parent
26db1ea66d
commit
872d650b3d
4 changed files with 29 additions and 5 deletions
|
@ -13,7 +13,7 @@ public partial class Interactable : Node2D
|
|||
|
||||
[Export] public Vector2 SpriteOffset;
|
||||
[Export] public float AreaRadius;
|
||||
|
||||
[Export] public bool IsEnabled;
|
||||
private AnimatedSprite2D _sprite;
|
||||
|
||||
private CollisionShape2D _areaMesh;
|
||||
|
@ -46,11 +46,20 @@ public partial class Interactable : Node2D
|
|||
if (_sprite.Position != SpriteOffset) _sprite.Position = SpriteOffset;
|
||||
if (Math.Abs(_collisionCircle.Radius - AreaRadius) > Tolerance) _collisionCircle.Radius = AreaRadius;
|
||||
}
|
||||
|
||||
if (IsEnabled)
|
||||
{
|
||||
_sprite.Visible = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_sprite.Visible = false;
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_area_2d_body_entered(Node2D body)
|
||||
{
|
||||
if (body is Player player)
|
||||
if (IsEnabled && body is Player player)
|
||||
{
|
||||
_sprite.Visible = true;
|
||||
EmitSignal(SignalName.PlayerNearBy, player);
|
||||
|
@ -59,7 +68,7 @@ public partial class Interactable : Node2D
|
|||
|
||||
private void _on_area_2d_body_exited(Node2D body)
|
||||
{
|
||||
if (body is Player player)
|
||||
if (IsEnabled && body is Player player)
|
||||
{
|
||||
_sprite.Visible = false;
|
||||
EmitSignal(SignalName.PlayerLeft, player);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue