Код: Выделить всё
using Godot;
using System;
using DialogueManagerRuntime;
public partial class ObjectInteract : Node {
private Resource dialogue = GD.Load("res://Dialogue/Test.dialogue");
private bool isInDialogue = false;
/*
Function Desc: Gets the distance between an object and the player via slope
@param ObjectX -> x-coordinate of the Object
@param ObjectY -> y-coordinate of the Object
@param PlayerX -> x-coordinate of the Player
@param PlayerY -> y-coordinate of the Player
*/
public float getDistanceSlope(float ObjectX, float ObjectY, float PlayerX, float PlayerY){
float dx = ObjectX - PlayerX;
float dy = ObjectY - PlayerY;
float distance = dx * dx + dy * dy;
float trueDistance = (float)Math.Sqrt(distance);
return distance;
}
/*
Function Desc: Checks whether the player is close enough to interact with the object
@param slope -> Distance between object and player
@param objectName -> Name of the object
*/
public void checkInteract(float slope){
if (slope < 850 && Input.IsActionJustPressed("interact") && !isInDialogue){
DialogueManager.ShowExampleDialogueBalloon(dialogue);
isInDialogue = true;
DialogueManager.DialogueEnded += checkDialogueFinished;
GD.Print("Event fired!");
}
}
private void checkDialogueFinished(Resource dialogue) {
GD.Print("Event ended, setting isInDialogue back to false!");
isInDialogue = false;
DialogueManager.DialogueEnded -= checkDialogueFinished;
}
}
Подробнее здесь: https://stackoverflow.com/questions/794 ... nded-event