Hello guys, thanks for taking the time to help me out.
I'm running into a bit of a problem in my game I'm working on.
The script is working correctly at runtime; and when I encounter enemies, the combat gets loaded and set up correctly.
However, when I run the combat 'for each' loop that iterates through each member in a combat list, I get this error:
I think I traced it to this particular block of code circled in the image below. I think the exception might be thrown because the script is trying to access the variable between value changes...
While I have learned a lot about C# in the past few weeks, I am still relatively new to coding. After doing some research, I am unable to find what the issue is.
I've attached the entire script if you have the time to look at it.
http://pastebin.com/UnvifGZC
Replies
public List<string> combatList; = new List<string>();
also, you should get in the habit of not using var.
I should note that before I added the bit to make characters turn and rotate to face active defenders/attackers, the for loop was iterating successfully.
Can you put in a debug.log(value); after the foreach loop?
And converting that to string might not be possible unless you've given it that ability.
I suspect you want activedefender.name or something. So that it's a string.
But specifically, the code block that you have highlighted references ActiveDefender.ToString() but ActiveDefender has not been initialized before that code executes, so it must be a null value. Nor has Active Combatant for that matter.
You might just break the lookat bit into its own little function: then modify your combat loop to be something like
Turns out two variables weren't getting values before it hit the for each loop.
Much appreciated!