unity-game-engineunity3d-editor

Unity, how to have multiple 2D collider on single object


I have a tower defense game. I want to modify the walk animation of ennemies, so that depending of their position on the map, i can use front, left, right walk animations.

I want to use 2D colliders, so that when an ennemies enter inside the new zone, i can detect with TriggerEnter and change the animation of the Walk.

Which kind of collider should i use to achieve this ? I mean, Which collider should I use to have different colliders side by side like in the image ?

Thanks.

enter image description here

Update: In this example you can see ennemies moving following a path and in this situation, i should detect the position to have another animation, for example profile walk. enter image description here


Solution

  • I finally used this solution. Thank you all

                Vector2 currentDirection = (points.ways[wayIndex].wayPoints[wayPointIndex].position - transform.position).normalized;
            if (Mathf.Abs(currentDirection.x) >= Mathf.Abs(currentDirection.y))
            {
                //Character is moving sideways
                if (currentDirection.x > 0)
                {
                    print("Move Rigth");
                }
                else
                {
                    print("Move Left");
                }
            }
            else
            {
                //Character is moving straight
    
                if (currentDirection.y > 0)
                {
                    print("Move Up");
    
                }
                else
                {
                    print("Move Down");
    
                }
            }