startingState
gets assigned to state
, not the other way round. Why the startingState
variable? Because we want to restart our game at some point. The computer does not know what our first start is, and it does not remember anything unless we assign something to a persistent variable.
The variables startingState
and state
hold a reference to a State object. You assign something to state
according to your logic. Unity does not care which State object is referenced. It does not read any stories, only humans do.
(Once upon a time…blah blah) (DOT) GetStateStory ()
Assuming you assign your A1 object to state
. state.GetStateStory()
will return the story stored in the A1 object. When you assign B192 to state
, the same line of code, state.GetStateStory()
, will return the story stored in the B192 object. And so on.
And that’s modern programming. You do not hard-code anything but write general code you can feed with data, and that data gets processed in accordance with your predefined rules.