F
F
FixMyLife2017-10-29 23:02:15
C++ / C#
FixMyLife, 2017-10-29 23:02:15

onTriggerEnter2D and onCollisionEnter2D don't work, what could be wrong?

when entering the trigger, onTriggerEnter2D does not work, the same situation with onCollisionEnter2D
code onTriggerEnter:

public void onTriggerEnter2D(Collision2D coll)
{
  Debug.Log("Enter");
  
  if(coll.gameObject.name == "bonus")
  {
    Destroy(coll.gameObject);
    score++;
  }
}

onCollisionEnter2D code:
public void onCollisionEnter2D(Collision2D col)
{
  if (col.gameObject.tag == "enemy")
  {
    NewBehaviourScript im = col.gameObject.GetComponent<NewBehaviourScript>();
    im.Death();
  }
}

death function from NewBehaviourScript:
public void Death()
{
  if(isAlive)
  {
    anim.SetBool("isAlive",false);
    speed = 0;
    transform.GetComponent<Collider2D>().enabled = false;
    isAlive = false;
  }
}

59f633b0cc53d532703064.jpeg59f633bb59de9548705799.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Daniil Basmanov, 2017-10-30
@FixMyLife

OnTriggerEnter2D and OnCollisionEnter2D are capitalized.

G
Griboks, 2017-10-30
@Griboks

It's worth trying to include triggers using rigidbody

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question