- Home /
Not Sure How to Assign State Name to State Variable
Hello!
I hope this is the right place to ask this. I'm currently taking an Udemy course on how to work and code in the Unity engine and in the second lecture, we are creating a text adventure game. For this, they have us working with arrays and states (to add in the story text). I had the idea that the player's certain choices will lead them to different endings. I pondered on how to do this that doesn't require an arduous or inefficient method and it hit me that I could program a method that checks if the player has been in a certain state and will send them to a particular ending state depending if that's true or false.
I have already consulted the Q&A forum of the course for how to do this, where I was told to "hard-code" my rules, but my question today is because of some confusing language.
With state.name, you can get the name of the current state. Log the values into your console to get an idea of what is happening while you are running your code.
You could create one State variable for each state you need for your logic, for instance, state1, state2, state3. Assign the respective State objects to them. Also add 3 bools.
Then use a bunch of if-statements to
a) compare the name current scene to the name properties of your variables. If true, set the respective bool to true. b) check if the bools are true or false or whatever to determine which ending you want. This must be hard-coded, too.
How do I/what do they mean exactly by "Assign the respective State objects to them" as doing anything like States state1 = Name of My State;
is obviously illegal. And I tried doing something like States[6] = state1;
but the program also said that "States[6]" was illegal (which makes sense now that I think about it). So, perhaps I'm misunderstanding what this user means? I have asked them but they have yet to respond. Would anyone know perhaps what they mean and/or how to do that?
Thank you for reading.