I have 2 game objects, lets say them A and B
A has a 2D box collider and isTrigger is selected and this A object is sign static. B has a 2D box collider too and its isTrigger also activated. B also has a kinematic rigidbody2D.
When these two game objects collide with each other OnTriggerEnter2D(Collider2D other) function is only fired on object A not on object B. It is also not fired when two B game objects collides. What am I doing wrong? Any help is appreciated.
Thank you people.
Hey Guys, sorry for late response, I really appreciate your help, so first of all thank you.
Below I add some images and code blocks as @tanoshimi requested.
One of my objects which is moving across screen:
The collectible standing still object:
here is my player code block for ontrigger:
void OnTriggerEnter2D(Collider2D other)
{
Debug.Log("hoorey");
}
and collectible ontrigger:
void OnTriggerEnter2D(Collider2D other)
{
GameObject head = other.GetComponentInParent<PlayerController>().head;
GameObject tail = other.GetComponentInParent<PlayerController>().tail;
head.transform.localScale = new Vector2(head.transform.localScale.x * 1.5f, head.transform.localScale.y * 1.5f);
head.transform.localPosition = new Vector2(0,0);
tail.transform.localScale = new Vector2(tail.transform.localScale.x * 1.5f, tail.transform.localScale.y * 1.5f);
tail.transform.localPosition = new Vector2(0, tail.transform.localPosition.y + tail.transform.localPosition.y/2);
other.GetComponentInParent<PlayerController>().UpdateHealth(10.0f);
Destroy(gameObject);
}
m0guz
September 10, 2016, 7:43am
3
I read your posts, other possibility is Layer-based collision detection
First check object’s layer in Inspector window, then Go to Edit > Project Settings > Physics2D and check if layer is selected.