Nonworking script

This commit is contained in:
Marco 2025-01-22 16:19:54 +01:00
commit 7b8abba100
3 changed files with 42 additions and 15 deletions

View file

@ -3,25 +3,55 @@
[Tool]
public partial class DoorButtonVisualizer : Node2D
{
[Export] public NodePath TargetPath; // Expose the Target NodePath in the editor
// [Export] public NodePath TargetPath; // Expose the Target NodePath in the editor
// public override void _Ready()
// {
//
// }
private Interactable _parent;
public override void _EnterTree()
{
var p = GetParent();
if (p == null) return;
if (p is Interactable parent)
{
_parent = parent;
}
//if (_parent == null) return;
}
public override void _Draw()
{
if (TargetPath == null || !Engine.IsEditorHint())
return;
//var parent = GetParent<Interactable>();
if (_parent != null) return;
//if (GetParent() is not Interactable parent) return;
if (!Engine.IsEditorHint()) return;
// if (TargetPath == null || !Engine.IsEditorHint())
// return;
if (_parent is not Interactable p) return;
if (p.Target == null) return;
// Get the target node
Node targetNode = GetNodeOrNull(TargetPath);
if (targetNode == null || !(targetNode is Node2D target))
return;
// Node targetNode = GetNodeOrNull(TargetPath);
// if (targetNode == null || !(targetNode is Node2D target))
// return;
// Draw a line to the target
Vector2 start = GlobalPosition;
Vector2 end = target.GlobalPosition;
var start = GlobalPosition;
var end = p.Target.GlobalPosition;
DrawLine(ToLocal(start), ToLocal(end), Colors.Green, 2);
}
public override void _Process(double delta)
{
// Update the visualization in the editor