At this point I’m desperate. I just can’t get that thing to work.
I’ve got two prefabs initiated through code
void Start()
{
first = Instantiate(Resources.Load("poke"), new Vector3(), Quaternion.identity) as GameObject;
second = Instantiate(Resources.Load("poke"), new Vector3(), Quaternion.identity) as GameObject;
first.AddComponent<Rigidbody2D>();
second.AddComponent<Rigidbody2D>();
first.AddComponent<CircleCollider2D>();
second.AddComponent<CircleCollider2D>();
first.gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
second.gameObject.GetComponent<Rigidbody2D>().gravityScale = 0;
}
Both of them now have a rigidbody and a collider. Triggers are of. kinematic property is off. Gravity is set to zero. When the objects collide, they act like they should, bumping into eachother but the event won’t fire.
void OnCollisionEnter2D(Collision2D collision)
{
Debug.Log("collision");
}
I tried moving the objects by transforming their position and by adding Force to them.
What is going on?