Not sure if I missed something, or this was not covered, but if the selected unit at the end of my turn dies during the enemy turn, they are taken off the unit lists correctly, but when the game turns back to my turn, they are still the selectedUnit in the UnitActionSystem, meaning that the game displays valid grid positions for the dead units selected action. If I click on any of those squares, I get a very understandable error.
I fixed this by changing Die in Unit to set the selectedUnit in the UniActionsSystem to the first one in the friendlyUnitList, if the list.count > 0.
private void Die()
{
OnDead?.Invoke(this, EventArgs.Empty);
List<Unit> friendlyUnitList = UnitManager.Instance.GetFriendlyUnitList();
if (friendlyUnitList.Count > 0)
{
UnitActionSystem.Instance.SetSelectedUnit(friendlyUnitList[0]);
}
}
To do this, I had to make SetSelectedUnit public. Now arguing with myself is this is the correct way, or to get the UnitActionSystem to subscribe to an event. I’m going with the above method as the UAS is a singleton, but happy to be convinced otherwise (or an even better solution, of course).
I enjoyed the recent devology that CodeMonkey guested on. Good stuff. One of my mental blocks is adding my first iterations of code to the code produced by 5 months of hard work for a course. It seems like sacrilege. This (and Nathan’s 3d combat course) have got me thinking it is better to write my code in a separate class that extends what we do in the courses? Just tag the methods as virtual and copy them into my class and tinker with them there. That way, when I break them, I don’t break the game, and I don’t disturb the surrounding code. Hmm. One to play with.