I dont understand the reason that i get the error:
I realy have no idea this is my code:
using System.Collections.Generic;
public class Snake : MonoBehaviour
{
List<GameObject> snake = new List<GameObject>();//list of the snake
Vector3 position2 = (new Vector3(0, 0, 0));//as it is needed to move the tail so make sure it starts at 0 :smile:
//void Awake ()
//{
// Vector3 position = transform.position;
//}
void Update ()
{
transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, 10));//the mouse follows the mouse
float distance = Vector3.Distance(transform.position, position2);//checks the distance from your position to position2(last move)
if (distance >= 0.25)//checks if you have moved far enough
{
print ("far =" + distance);//just printing for debug
//Move tail
movetail();
position2 = transform.position;//changes position2 because you have moved more then 0.25
}
}
void movetail()
{
int snakepart = 0;
if (snakepart <= snake.Count)
{
int snakepart2 = snakepart ++;
print ("To long");
GameObject snakebit1 = snake <snakepart>;
GameObject snakebit2 = snake <snakepart2>;
snakebit1.transform.position = snakebit2.transform.position;
}
snakepart ++;
}
}
I think i maby should be using arrays and not lists? but someone said that lists are faster? can i not use a list for this?
Thanks,
Tyler