Сцена для интерактивных объектов
This commit is contained in:
parent
42db203fca
commit
cf7f3bee5b
2 changed files with 66 additions and 0 deletions
42
scripts/Interactable.cs
Normal file
42
scripts/Interactable.cs
Normal file
|
@ -0,0 +1,42 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class Interactable : Node2D
|
||||
{
|
||||
[Export] public Vector2 SpriteOffset;
|
||||
[Export] public float AreaRadius;
|
||||
|
||||
private AnimatedSprite2D _sprite;
|
||||
|
||||
private CollisionShape2D _areaMesh;
|
||||
|
||||
// Called when the node enters the scene tree for the first time.
|
||||
public override void _Ready()
|
||||
{
|
||||
_sprite = (AnimatedSprite2D)FindChild("AnimatedSprite2D");
|
||||
_areaMesh = (CollisionShape2D)FindChild("CollisionShape2D");
|
||||
_sprite.Position += SpriteOffset;
|
||||
((CircleShape2D)_areaMesh.Shape).Radius = AreaRadius;
|
||||
}
|
||||
|
||||
// Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
}
|
||||
|
||||
private void _on_area_2d_body_entered(Node2D body)
|
||||
{
|
||||
if (body is Player player)
|
||||
{
|
||||
_sprite.Visible = true;
|
||||
}
|
||||
}
|
||||
|
||||
private void _on_area_2d_body_exited(Node2D body)
|
||||
{
|
||||
if (body is Player player)
|
||||
{
|
||||
_sprite.Visible = false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue