toggle animator bool when in a collider

Hello, Im fairly new to c# and can’t find a way to apply a toggle on a bool.
Thank you for your help!

I am trying to create an information zone.
When the player enter a collider, a text appears saying “press use key” to read.
Then an animation pulling the information text in and out the screen is controlled by a bool named “slide”.

I would like to set the boolean controlling the animation to true or false with a single key while in the collider, so the player can either move away from the collider or press “use” again to exit the text.

With the following code I only press “use” once and move away from the collider to make disapear.
I am sure there is a simple solution to this but smh can’t apply it. Thanks again!!

  using System.Collections;
    using System.Collections.Generic;
    using UnityEngine;
    
    public class OnTriggerLoadconversation : MonoBehaviour
    {
      [SerializeField] private Animator myAnimationController;
      public GameObject enterText;
    
      void Start()
      {
        myAnimationController.SetBool("slide", false);
        enterText.SetActive(false);      
      }
    
      // Update is called once per frame
      void OnTriggerEnter(Collider plyr)
      {
          if (plyr.gameObject.tag == "Player")
          {
            enterText.SetActive(true);
    
              if (Input.GetButtonDown("Use"))
              {
                myAnimationController.SetBool("slide", true);
                enterText.SetActive(false);
    
              }
          }        
      }

      void OnTriggerStay(Collider plyr)
      {
          if (plyr.gameObject.tag == "Player")
          {
    
              if (Input.GetButtonDown("Use"))
              {
                myAnimationController.SetBool("slide", true);
                enterText.SetActive(false);
    
               }
            }
      }

      void OnTriggerExit(Collider plyr)
      {
          if (plyr.gameObject.tag == "Player")
          {
            myAnimationController.SetBool("slide", false);
            enterText.SetActive(false);
    
         }
      }
    }

So I made it work with the following solution.
It still seem a bit buggy. (for some reason it doesn’t seem to work every time)
I am open if any body has something more elegant :slight_smile:

So this is applied to my collider object.
The ui object (press x to display info) is called “enterText”.
The bool that animate the actual information text in and out screen is called “slide”, and Is toggled false or true to make it move.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class OnTriggerLoadconversation : MonoBehaviour
{
  [SerializeField] private Animator myAnimationController;
  public GameObject enterText;

  void Start()
  {
    enterText.SetActive(false);
    myAnimationController.SetBool("slide", false);
    }

   // Update is called once per frame
    void OnTriggerEnter(Collider plyr)
  {
      if (plyr.gameObject.tag == "Player")
      {
        enterText.SetActive(true);       
      }
  }

void OnTriggerStay(Collider plyr)
  {
      if (plyr.gameObject.tag == "Player")
      {
            if (Input.GetButtonDown("Use"))
          {
   myAnimationController.SetBool("slide", !myAnimationController.GetBool("slide"));
   enterText.SetActive(!enterText.activeInHierarchy);
          }
        }
  }

   void OnTriggerExit(Collider plyr)
    {
        if (plyr.gameObject.tag == "Player")
        {
       enterText.SetActive(false);
       myAnimationController.SetBool("slide", false);
        }
    }
}