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…
What is the activedefender variable? It seems to me like if be a class or struct. 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.
I don't see anything obvious that would cause the combatList to be null. It looks like it shouldn't be able to get into that loop to throw that error on var targetLookPoint = GameObject.FindWithTag(value); Can you put in a debug.log(value); after the foreach loop?
you simply have something in the list which is there but null.. maybe because it was destroyed or something.. best way imo is to simply check inside the foreach that your next object in combatList is what you expect.. and that is not null
Thanks electricsauce. 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.
I don't see the list being instantiated anywhere: public List<string> combatList; = new List<string>(); also, you should get in the habit of not using var.
I think Farfarer got it. 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…