I’m trying to instantiate a prefab, and saving it in a List. But I do have some troubles doing this.
the spawnSnake()
method will spawn the objects, but when I look into the inspector, I see that the elements are set to ‘None (Box Collider 2D)’.
I need to access the objects spawned within my code, but can’t figure out how. Even though I’ve been searching through the forums.
What I have so far:
public Transform snakeTransform;
public List<BoxCollider2D> snake = new List<BoxCollider2D> ();
void Start () {
spawnSnake ();
}
void spawnSnake(){
for (int i=0; i<3; i++) {
snake.Add( Instantiate (snakeTransform, new Vector3(-(boardSize*tileSize/3), -3+i, 1), Quaternion.identity) as BoxCollider2D);
}
}