This script adds three different 2D colliders to the same GameObject and prints their properties.
using UnityEngine;
public class ColliderExample : MonoBehaviour
{
void Start()
{
// Add a BoxCollider2D
var box = gameObject.AddComponent<BoxCollider2D>();
box.size = new Vector2(2f, 3f);
// Add a CircleCollider2D
var circle = gameObject.AddComponent<CircleCollider2D>();
circle.radius = 1.5f;
// Add a PolygonCollider2D
var polygon = gameObject.AddComponent<PolygonCollider2D>();
polygon.points = new Vector2[] {
new Vector2(0, 0),
new Vector2(1, 0),
new Vector2(1, 1),
new Vector2(0, 1)
};
Debug.Log("Box size: " + box.size);
Debug.Log("Circle radius: " + circle.radius);
Debug.Log("Polygon points count: " + polygon.points.Length);
}
}