0
\$\begingroup\$

enter image description here

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

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

enter image description here

The animator and script are on the bubble itself.

enter image description here

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. Not only that, but I also tried to make it public and referenced it, still nothing.

Help me see my mistake :)

\$\endgroup\$
4
  • \$\begingroup\$ Does the player actually have a tag "Player" (not a layer)? Does it have a 2Dcollider and a rigidbody? \$\endgroup\$
    – R.K.
    Commented Mar 13, 2020 at 13:40
  • \$\begingroup\$ @R.K. Yes, player is tagged Player. And he has both a rigid body and a 2D collider. \$\endgroup\$
    – AHAKuo
    Commented Mar 13, 2020 at 14:37
  • \$\begingroup\$ Could you also provide a screenshot of the player settings? Also according to the tag checking, consider using other.gameObject.tag == "Player". Also I am not sure if the OnTriggerEnter also works, if the actual collider is on the parent object. You could try boxCollider.OnTriggerEnter (and set the collider to public). \$\endgroup\$
    – R.K.
    Commented Mar 13, 2020 at 14:43
  • \$\begingroup\$ Hi, thank you for trying to help. It turned out that moving the conditions script to the same object that has the collider fixed it. I don't know why it worked, but it did. \$\endgroup\$
    – AHAKuo
    Commented Mar 13, 2020 at 14:45

1 Answer 1

0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ Physics messages like OnTriggerEnter2D are called on the object that contains the collider and on the object containing the collider's Rigidbody, if any. It doesn't recurse down to child objects of the parent with the collider. \$\endgroup\$
    – DMGregory
    Commented Mar 13, 2020 at 16:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .