Connecting Signals and C#

Godot Version

4.2 Mono

Question

Im trying to connect to the on_body_entered signal however I can’t seem to figure out what that actually looks like in C#. in GD script when you connect a signal it automagically shows up in the script

this is what i have now just so i could test to make sure collision was working but obviously this wont do for actual gameplay

using Godot;

public partial class LineOfSight : Area2D
{
	public override void _Process(double delta)
	{
		var body = GetOverlappingBodies();
		GD.Print(body);
}

Got it all figured out

using Godot;

public partial class LineOfSight : Area2D
{
	private Node2D player;
	void MyBodyEventHandler(Node2D body) 
	{
		if (body == player)
		{
			GD.Print("Player Found!");
		}
	}
	
	public override void _Ready()
	{
		BodyEntered += MyBodyEventHandler;
		player = GetTree().GetFirstNodeInGroup("Player") as Node2D;
	}

	
}

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.