Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

OnTriggerEnter2D is not working

Discussion in '2D' started by akkayaozi44, Apr 19, 2020.

  1. akkayaozi44

    akkayaozi44

    Joined:
    Apr 18, 2020
    Posts:
    11
    Hello everyone

    I have block. You can see properties of block on photo. I want if the boomerang bump to block, boomerang stop moving. The problem is my boomerang is never stop. So OnTriggerEnter2D function is not working. What is the problem ?


    Untitled.png


    Block=Instantiate(Platform, new Vector3(Random.Range(-2.5f, 2.5f), Random.Range(Boomerang.transform.position.y + 2, Boomerang.transform.position.y + 3f), 10), Quaternion.identity);




    void OnTriggerEnter2D(Collider2D col)
    {
    if(col.gameObject.tag== "asd")
    {
    Debug.Log("dsfsdf");
    Boomerang.transform.position += new Vector3(0, 0, 0);
    Boomerang.transform.Rotate(0, 0, 0);

    }
    }
     
  2. akkayaozi44

    akkayaozi44

    Joined:
    Apr 18, 2020
    Posts:
    11
    I also active isTrigger but the problem is still same
     
  3. McNookie123

    McNookie123

    Joined:
    Mar 7, 2018
    Posts:
    1
    Do you have a rigidbody and collider on the boomerang?
     
  4. NullBy7e

    NullBy7e

    Joined:
    Mar 20, 2020
    Posts:
    7
    Do you get the debug message in the console from the OnTriggerEnter2D function?
    Set IsTrigger on the collider and make sure that the collider is the right size so that it covers the entire block.