Make dialogue repeat when triggered.

This dialogue is triggered with a seperate script using OnTriggerEnter2D and Input.GetKeyDown, but when i try to trigger again, nothing happens. The script is on an object which has an UI Text and Sound etc as children.

public class DialogController : MonoBehaviour
    {
        public Text textDisplay;
        public string[] sentences;
        private int index;
        public float typingSpeed;

    public AudioSource audioSource;

    public AudioClip typingSound;

    private bool isTyping = false;

    private bool finished = false;

   

    public void Start()
    {

        StartCoroutine(Type());
   
        PlayerController.PlayerControlsEnabled = false;

        WitchController.WitchControlsEnabled = false;
    }


    void Update()
    {
        if(!isTyping && Input.GetKeyDown(KeyCode.E))
            {
                NextSentence();
            }


        if(finished == true)   
           {
               index = 0;
               this.gameObject.SetActive(false);
           }
           
    }

    public IEnumerator Type()
    { 
        isTyping = true;

        foreach(char letter in sentences[index].ToCharArray())
        {
            textDisplay.text += letter;
            audioSource.PlayOneShot(typingSound);
            yield return new WaitForSeconds(typingSpeed);

            
        }

        isTyping = false;
    }

    public void NextSentence()
    {

        if(index < sentences.Length - 1)
        {
            index++;
            textDisplay.text = "";
            StartCoroutine(Type());
        }
        else
        {
             finished = true;

             textDisplay.text = "";


             PlayerController.PlayerControlsEnabled = true;

             WitchController.WitchControlsEnabled = true;

             
        }
    }

Haven’t tested my theory so is still just a theory BUT I believe that the issue is because you’re never setting your ‘finished’ flag back to false.

This means that after we’ve completed the dialogue the first time, this gameobject will be set to inactive each frame and the index reset to 0.