I am new the unity tool, I have to develop a snake game at present i am doing this one. Till now i did scripting for the snake movement part, can any one help me out with the food for the snake and after eating that food snake tail should grow right. Now I am working on this part can any one help me with this part of the game. I mean if some one have the working java script for this snake game please post over here.
Usually when people develop snake games, they go for a tiled approach, i.e. define a 2D-surface of x times y tiles and store them in a 2-dimensional array. Is that what you have? I would probably have a Snake GameObject which contains an integer which is its length.
Then you have a Queue which contains the coordinates of the tiles that the snake occupies at any given point. It should be a Queue, because the tiles the Snake occupies enter and leave the data-structure in a First-In-First-Out manner: A tile which the head enters will leave the list of occupied tiles before any tile the head enters thereafter.
You call the Queue's Enqueue and Dequeue methods in a way governed by the integer that controls the Snake's length. I.e., whenever the snake moves, you Enqueue the new tile, and call Dequeue to remove the tile at its tail. Then when the snake eats, you increase the integer that governs the maximum size of the Queue of occupied tiles, so that the tiles the head enters the next, say, 3 times get added to the Queue without dequeuing the tail tiles. That will cause the snake's head to move forwards without the tail following.
That's how I'd do it. :)