- Home /
How to structure code for squad selection and movement
I'm trying to work out how to structure my code in a good way. I'm trying not to use MonoBehaviour unless I have to use their functions, but I'm having some issues.
I have a Squad class that contains an array of Unit objects, and a TacticalMap object. These units need to be represented in the scene however, so I have them create a unit prefab at initialization saved as a variable in the unit class, which is moved when the unit is moved. Is this a typical thing to do? Is seems strangle to have a unit class as well as a gameobject.
Anyway I would like to be able to select units. So I will need a new script that uses Monobehaviour (for OnMouseEnter()) attached to the unit prefab. I will need to know which unit is selected, so I make a public static variable that holds this gameobject. I'm not sure whether it's proper to use static variables in this way.
I have road GameObjects that also have scripts checking OnMouseEnter(), and when a destination in clicked-on, and when this happens the Squad class should move the unit there. I don't know how to set up this link though.
I was wondering if someone could give me suggestions how to structure a Unity project that does this?
Additionally, any tips/resources on how I can learn to structure my code well in Unity generally would be helpful.