I have a question about the Unity 2D course on the lecture with the title: Manage Next States.
I get confused at minute 2:20 when the instructor writes down the variable of type var on line 27. So far I understood that the variable var was a type of variable that you can use when you don’t want to specify the exact variable, so it’s there just to be used if you want to. In fact, the instructor says that var can be replaced with State. I don’t get why it’s possible to use var instead of State.
If state.GetNextState (in the AdventureGame.cs script) means that we are calling the public method GetNextStates from the State.cs script, which returns the array nextStates, how is it possible that a variable can now store an entire array of the current state?
It would be like writing down this:
the variable called nextStates has the array (from the other script) of the state we are currently in, assigned to it.
Now I’m asking myself: how is it possible that we’re taking the array from one script and putting it into a variable which has the same name as the array in the other script?
Using the array of type State would then make more sense because you would be storing an array into an “empty” array with the same name (nextStates).
Is var maybe being converted to whatever type it is equal to?
As you probably can tell I feel a bit frustrated now. So far I think I understood everything well, except some minor things that are still a bit confusing.
I think I’m asking myself these question because I misunderstood something.
I hope I was clear enough to get an answer I can work with.
If I wasn’t clear it would be enough if you could just explain to me what the lines 25-28 actually mean.
Thanks in advance!