While OnCollisionEnter2D(Collision2D collision) requires “transform” within “collision.transform.tag” (game will not even start showing compilation error) for OnTriggerEnter2D(Collider2D collision) it doesn’t really matter if there is this word and game works fine in both cases. Why? Things have to make sense.
More details.
Game is kind of Flappy Firefly. If the bird hits the ground - our player looses (Collision2D). If the tagged items (Collider2D) collide with bird, then they move further to have the background instead of the black screen.
//player
void OnCollisionEnter2D(Collision2D collision)
{
if(collision.transform.tag != "Sky") //player looses if he hits anything other then sky
{
Time.timeScale = 0f; //pauses imediately
Debug.Log("Game Over");
}
vs
//collider
private void OnTriggerEnter2D(Collider2D collision)
{
//if(collision.tag == "Background") can also be used
if(collision.transform.tag == "Background")
{
//getting width and starting position
float widthOfObject = ((BoxCollider2D)collision).size.x;
Vector3 position = collision.transform.position;
//changing object coordinates
position.x += widthOfObject *1.99f;
//setting a new position
collision.transform.position = position;
}
}