So i want my player to move up to a sign on a wall with a trigger, which will then show the text “E to interact”, that bit I worked out but i want an UI image to show up when my player is inside the trigger and presses E but i can’t seem to detect the trigger and input at the same time.
[SerializeField] private Image instructImg;
private bool isTouching;
private void OnTriggerStay2D(Collider2D other)
{
if (Input.GetKeyDown("e"))
{
isTouching = true;
}
}
private void OnTriggerExit2D(Collider2D other)
{
isTouching = false;
}
private void Update()
{
if (isTouching)
{
instructImg.enabled = true;
}
else
{
instructImg.enabled = false;
}
}
This is all i got right now, I have tried a some other approaches but none of them seem to work. Would really appreciate some help with this, thank you.