Disabling Interactable

How would we go about letting a unit interact with something only one time; for example, allow a door to be opened once and then not closed? I am not sure how to do that seeing as we need the Interact class with IInteractable.

If you know you will never need to close the door, you could simply destroy the script after the interaction with

Destroy(this);

When passing this to the Destroy rather than gameObject, the script itself is destroyed leaving the gameObject intact.

1 Like

I tried putting that in the Update function of Door.cs after onInteractionComplete() but it’s still interactable. In addition, the game breaks when I interact with it again.

I answered too quickly, it would appear, forgetting that the interaction is registered with the LevelGrid.

Instead, call

LevelGrid.Instance.ClearInteractableAtGridPosition(gridPosition);

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

Privacy & Terms