@ShadyProductions’ answer was close, but had some big issues involved. It immediately disabled player controls on collision instead of when it was clicked on, and it relied on the player walking out of the collider to re-enable their controls, which… wouldn’t be possible.
For starters, (continuing from the previous answer), move the enabled flag to your PlayerControls script, or whatever else you call that script. This is mostly for good-practice reasons to keep it organized.
It should look something like this:
public class PlayerControls : MonoBehaviour
{
public static bool playerControlsEnabled = true;
HandleMovement()
{
if (playerControlsEnabled)
{
// Player controls in here
}
}
}
Here’s what your Clickable class should look like:
public class Clickable : MonoBehaviour
{
public bool playerInRange;
public Dialogue dialogue;
void Activate()
{
if (playerInRange)
{
FindObjectOfType<DialogueManager>().StartDialogue(dialogue);
PlayerControls.playerControlsEnabled = false;
}
}
private void OnTriggerEnter2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
playerInRange = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
if (other.gameObject.CompareTag("Player"))
{
playerInRange = false;
}
}
}
Next you’re going to want your DialogueManager script to re-enable the players controls whenever the dialogue box closes. Just access the bool the same way and set it to true again, and it should all be fine.
That step heavily depends on how that script works, but since we can’t see it, it’s up to you to figure that part out.