Why isn't my BoxCollider2D doing anything?

I’m trying to make a speech bubble appear when you approach the tutorial board.

154136-annotation-2020-03-13-154005.png

The bubble is there and it has its animation states “Appear” and “Disappear”

Appear is called OnTriggerEnter2D

Disappear is called OnTriggerExit2D

The collider is on the parent, tutorial board

The animator and script is on the bubble itself
Can’t add more images due to rules.

This is the script I have attached to the bubble, the conditions script.

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

public class Conditions : MonoBehaviour
{

    private Animator bubblecondition;
    private BoxCollider2D boxCollider;

    // Start is called before the first frame update
    private void Awake()
    {
        bubblecondition = this.GetComponent<Animator>();
        bubblecondition.Play("Disappear", 0, 1f);
    }
    void Start()
    {
        //bubblecondition.SetBool("Here", false);
        boxCollider = this.GetComponentInParent<BoxCollider2D>();
    }

    // Update is called once per frame
    void Update()
    {
        
    }

    public void OnTriggerEnter2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            bubblecondition.Play("Appear", 0, 0f);
        }
        else
        {
            return;
        }
    }

    public void OnTriggerExit2D(Collider2D other)
    {
        if (other.tag == "Player")
        {
            bubblecondition.Play("Disappear", 0, 0f);
        }
        else
        {
            return;
        }
    }
}

What am I doing wrong? I spent an hour trying to know why.
I even tried to have the console write a message on collision but it’s just dead.
Help me see my mistake :slight_smile:

SOLVED

I simply put the conditions script on the board itself and referenced the collider as private BoxCollider2D directly. This fixed it oddly. Don’t know exactly why that was happening.

Hi @AHAKuo, It looks like that If this script is on the Bubble, trigger is never going to fire because the object with the trigger collider is it’s parent object.

Not sure what you are trying to do with this:

boxCollider = this.GetComponentInParent();

but that does not make the parent object own the OnTrigger statements in this script. I’m guessing bubble does not have a trigger collider, nor would it work because (I gather) it’s inactive.

Put this script on the Tutorial Board. Then OnTrigger will catch the collision events.