Question by
Reinhardt70 · Aug 03, 2020 at 11:13 PM ·
ontriggerenter2d
How to have a sprite disappear on contact with another sprite, but then reappear on exit.
Hi all,
First time posting and still very new to Unity, so please be kind :)
I'm trying to have the text box sprite appear and disappear based on whether or not the player (Banana) has collided with the sign post. Please see the attached image:
Here is the code that I have written:
public class PopUpImage : MonoBehaviour {
public SpriteRenderer popUp;
private void Start()
{
popUp = GetComponent<SpriteRenderer>();
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
popUp.enabled = false;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
if (collision.CompareTag("Player"))
{
popUp.enabled = true;
}
}
I set the Sprite Render to be the text box (CollisionText1) but when I touch the sign post, the post disappears and reappears instead of the Text Box Sprite.
Would anyone know why this might be the case?
Thanks in advance!
capture.png
(167.2 kB)
Comment
Your answer