I have a stationary sprite with the tag “Player” with a Rigidbody2D (dynamic body type and discrete collision detection) and circle collider 2D.
I also have a moving UI image; also with a Rigidbody2D (dynamic body type and discrete collision detection) and circle collider 2D.
I want to detect when the moving UI Image collides with the sprite, however I’m not getting the print statement inside of the OnCollisionEnter2D() function below whenever I see them collide on the screen.
public class MeteorController : MonoBehaviour
{
Vector3 newPos;
// Start is called before the first frame update
void Start()
{
xCoor = transform.localPosition.x;
yCoor = transform.localPosition.y;
newXCoor = xCoor * -1;
newYCoor = yCoor * -1;
newPos = new Vector3(newXCoor, newYCoor, 0);
}
// Update is called once per frame
void Update()
{
transform.Translate(newPos * Time.deltaTime * speed);
}
void OnCollisionEnter2D(Collision2D coll)
{
if (coll.gameObject.tag == "Player")
{
print("PLAYER");
}
}
}