Snake game

Hi people.

I am coding a snake game in unity and i am having problems with it.

First, I want to instantiate some prefabs in a specific pattern which would be the length of the snake.

That would be the solution but…

tar: Transform;

function Update() {
    for (var i=0; i <= snakeSize; i++) {
	Instantiate(tar, Vector(tar.transform.position.x + i, 1, tar.transform.position.z),
		Quaternion.identity));
	}

But the problem is that the instances keep being created until the program crashes. I tried everything, putting loops and if statements to stop the instantiation process but it never stops.

And second, what would be the best way to create instances with different names, ids?

are there some ways to create different tags through scripting?

Thanks for any help further.

That’s because it’s in Update. Don’t use Update unless you actually want something to happen every single frame.

–Eric

If I use Instantiate function outside of Udpate function, it keeps creating instances with no stop.

I am just creating my instances using the editor itself to “fix” the problem.

This is some bug of 2.6.1 version?