[System.Serializable] public struct Car { public string model; public int speed; //Constructor to initialize the struct public Car(string vehicleName, int vehicleSpeed) { model = vehicleName; speed = vehicleSpeed; } //Method to display vehicle information public void DisplayVehicleDetails() { Debug.Log($"Model: {model}, Speed: {speed}"); } } public class StructListSample : MonoBehaviour { //List to store instance of the car struct. This can be modified through the Unity inspector since we serialized the struct. public List<Car> carList = new(); void Start() { //Add some cars to the list manually carList.Add(new Car("Porsche", 350)); carList.Add(new Car("Tesla", 500)); //Output the cars to the console foreach(Car car in carList) { car.DisplayVehicleDetails(); } } }