I’m writing a simple snake game. The snake’s body consists of several GameObjects (three by default, not counting the head). When starting the game, I want to add the body of the snake (its three objects) to the List. However, Unity gives me this error:
pointing to the last line in the code where I am trying to add an GameObject to the List.
At the same time, when I display the result of “GameObject.Find(bodyName)”, the game calmly finds this GameObject (as it should be):
However, when I try to add the same object to the List, the game starts to complain.
Here is the code snippet in question:
Sorry for such stupid questions. I just ran out of solutions. I wouldn’t even think that I’d be stuck on such a trifle
The error complained not about the object, but about the list itself, because it was not created, although it was declared. It seems that today I got up on the wrong foot