Okay, so I had code working for a Snake game in which, like the classic, you pick up an object, the score goes up and if you hit your tail or a wall it’s Game Over. But for some reason now the food does not destroy itself when picked up. I know I am hitting the food as the score goes up but the food doesn’t disappear then reappear.
Here is my collision code:
var player : GameObject;
var food : GameObject[];
var Tail : GameObject;
var lastTail : GameObject;
function Start () {
}
function Update () {
}
function OnCollisionEnter (collision : Collision)
{
if(collision.transform == player)
{
addTail ();
Destroy(gameObject);
var foodname = Instantiate(food[(Random.Range(0,food.Length))],
new Vector3(Random.Range(-48, 96), 1.5,
Random.Range(-23, 22)),
Quaternion.identity) as GameObject;
foodname.name = "Food";
}
}
function addTail ()
{
var newTail : GameObject = Instantiate(Tail, transform.position, Quaternion.identity);
newTail.name = "Tail";
newTail.GetComponent.<SmoothFollow>().target = lastTail.transform;
lastTail = newTail;
}