- Home /
Class lists not entirely working
I have two classes as well as my main script, and I'm putting the classes into lists to store information about weather types. The problem is, only one of them ever shows up as a list. I have tried switching the order around, and it is only ever the first of the two that gets shown. I get all kinds of errors when working on the other one, and I'm not sure about what to do to fix it.
My code (I removed the irrelevant stuff):
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
[System.Serializable]
public class RainTypes
{
public Object rainPrefab;
public Color fogColour;
public float fogStart;
public float fogEnd;
public Color ambientLight;
}
public class WindZoneTypes
{
public float windMain;
public float windTurbulence;
public float windPulseMagnitude;
public float windPulseFrequency;
}
public class WeatherManager : MonoBehaviour
{
public List<RainTypes> rainTypes = new List<RainTypes>();
public List<WindZoneTypes> windTypes = new List<WindZoneTypes>();
}
Thank you for your time,
zedseven
Looking at the code I think what you're missing may be the fact that "[System.Serializable]" only applies to the class that immediately follows it. So add it before the second class definition too, and you should be able to see the elements of both when you have public instances visible in the Inspector.
But I may be missing the point of the question - it really isn't clear what you mean by things "not showing up in a list". If you mean the list(s) you create on lines 25-26, then from what you've posted it doesn't look like you put anything into those lists, so naturally nothing will show up in them!
That was absolutely what I was looking for. I just tested it, and it works perfectly now! Thank you very much, Bonfire Boy! By the way, I am adding things into the lists in the inspector, but I meant that the lists themselves weren't showing up.
Thank you again, zedseven
Answer by LawgiverSS2 · Jul 14, 2015 at 04:32 PM
Add [System.Serializable] before public class WindZoneTypes.
[System.Serializable]
public class RainTypes
{
public Object rainPrefab;
public Color fogColour;
public float fogStart;
public float fogEnd;
public Color ambientLight;
}
[System.Serializable]
public class WindZoneTypes
{
public float windMain;
public float windTurbulence;
public float windPulseMagnitude;
public float windPulseFrequency;
}
Your answer
Follow this Question
Related Questions
How to access individual class elements, that has an array, that is in a list for c# 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
How to carry List's and Vector3's to other classes? Interfaces don't work? 4 Answers
Access list storing custom class variables from another script 1 Answer