funtion oncollider

hi everyone im making a snake game and i want to know how can i create a script that when my player hit something add a ball to my player

Instantiate is how you would create the ball piece.

Then it depends on how you actually want the snake to function and look, as Warwick and Bovine say above.

The simplest way I can think to make an easy snake game is that each piece should aim to position itself next to the piece in front of it. Something like:

var target: Transform;

function Update() {

//Get Targets Position and subtract your own position to find the Vector that you want to travel

//Scale the vector
using Vector3.Normalize (sets the
distance to 1)

//Scale the vector to however far you want to travel in a single update

//Transform.translate the vector you end up with.

}

from there you can add more things, like instead of aiming directly at the target's position, offset it by a certain amount so they won't overlap.