- Home /
Why is my OnTriggerEnter2D(Collision2D other) function not working ?...
I've used Collider 2d in both the gameobject, Is trigger is also marked and used Rigidbody 2D in one of the gameobject and body type is also Dynamic, gravity is set to zero, But it's still not working I've checked everything is correct but it's still not working No "Warning" No "error" but it's still not working, Please, fellow programmers help me out, The Script I've written is mentioned below:
using System.Collections; using System.Collections.Generic; using UnityEngine;
public class Powerup : MonoBehaviour {
[SerializeField]
private float _speed = 4.0f;
// Update is called once per frame
void Update ()
{
transform.Translate(Vector3.down * _speed * Time.deltaTime);
}
void OnTriggerEnter2d(Collider2D other)
{
Debug.Log("Collided with: " + other.name);
/*
if(other.tag == "Player" )
{
Player player = other.GetComponent<Player>();
if(player != null)
{
player.canTripleFire = true;
}
Destroy(this.gameObject);
} */
}
}
Is the script attached to the object that the player is to collide with?
Does the Debug message appear in the Console?
Answer by Usama_S · Aug 17, 2018 at 11:53 AM
Change your method name to "OnTriggerEnter2D" and it will start working... Hopefully... :D ,This method is case sensitive and you have written "OnTriggerEnter2d" while the original one is with capitol "D" i.e "OnTriggerEnter2D"
Answer by mohammadzeinallpuor · Aug 17, 2018 at 11:42 AM
your script have working for my.
i think your problem is for option Rigidbody .
Answer by Ermiq · Aug 17, 2018 at 06:26 PM
Check the collision matrix in: upper-left corner of the screen -> Edit -> Project settings -> Physics2D
. Then in the inspector look at the matrix and check if layers of your objects are set to collide with each other.
Your answer
![](https://koobas.hobune.stream/wayback/20220612173001im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Using child colliders with rigidbodies/joints in 2D 0 Answers
Is it possible to have continuous collision detection with dynamic points on Edge Colliders? 0 Answers
How to select the trigger layer on a Box Collider 2D 2 Answers
2D dynamic collider for dynamic shape 0 Answers
Character slows down when running against a wall (2D) 1 Answer