Unity collision determination

Asked 2 years ago, Updated 2 years ago, 80 views

I'm a beginner who just started Unity.
I'm making a game with Unity, but I'm worried because I can't judge when the player and Enemy collide.
Specifically, the player's code is

void OnTriggerEnter 2D (Collider 2D col)
{   
    if(col.gameObject.CompareTag("ground"))
    {
        Debug.Log("Landing";
    }
    if(col.gameObject.CompareTag("Enemy"))
    {
        Debug.Log("Collision");
    }
}

However, if you look at the log, the landing on the ground is going well, but the log says "collision" twice even though there should be only one collision with Enemy.
How can one collision be handled once?
Thank you for your cooperation.

unity2d

2022-09-30 19:24

1 Answers

Is it a collider issue that is being used?
Please refer to this.

https://answers.unity.com/questions/1474400/ontriggerenter2d-gets-called-twice-sometimes.html


2022-09-30 19:24

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.