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);
}
}
}