Your code looks up game objects tagged with Weapon. Maybe none are found, in which case your next line is going to go wrong. I suspect that is what is causing the NullReferenceException. Or, maybe the `weapons` variable does have a GameObject, but that GameObject doesn't have a weapon component on it. In which case the Debug.Log line will cause a NullReferenceException. As I am sure you'll know from reading all the questions on this site tagged with `NullReferenceException` this happens whenever a variable isn't set to a value. You should never assume that a variable is assigned, so check that before using the variable.
↧