Can Someone help me fix this messy code and simplify it.
public List<Slot> FuelSlots = new List<Slot>();
public List<Slot> InputSlots = new List<Slot>();
public List<Slot> OutputSlots = new List<Slot>();
[Header("Furnace Slots")]
public GameObject FuelSlotOne;
public GameObject FuelSlotTwo;
public GameObject InputSlotOne;
public GameObject InputSlotTwo;
public GameObject InputSlotThree;
public GameObject OutputSlotOne;
public GameObject OutputSlotTwo;
public GameObject OutputSlotThree;
private Slot FuelOne;
private Slot FuelTwo;
private Slot InputOne;
private Slot InputTwo;
private Slot InputThree;
private Slot OutputOne;
private Slot OutputTwo;
private Slot OutputThree;
private void Start()
{
FuelOne = FuelSlotOne.GetComponent<Slot>();
FuelTwo = FuelSlotTwo.GetComponent<Slot>();
InputOne = InputSlotOne.GetComponent<Slot>();
InputTwo = InputSlotTwo.GetComponent<Slot>();
InputThree = InputSlotThree.GetComponent<Slot>();
OutputOne = OutputSlotOne.GetComponent<Slot>();
OutputTwo = OutputSlotTwo.GetComponent<Slot>();
OutputThree = OutputSlotThree.GetComponent<Slot>();
}
3 Replies
you can probably use a loop to store and get the slots
you already have these lists, why not use those?
You are misusing the concept of a
Field
and a Property
.
I don't know from where and when the Furnace Slots
are set, but here's an example:
No, absolutely not!
This is Unity, not normal C#
Just use an array if the size never changes (at runtime) and access by index. Simple as that.
1 . So for Unity, you cannot initialize a new instance of objects inheriting from UnityEngine.Object.
2. Unity does not like Properties as they are not serialized by the editor (by default), you can however do
[field: SerializableField]
but it isn't exactly worth the trouble.
3. Reflection is not recommended in Unity because it will cause a permanent overhead.