- Home /
How to Instantiate into a terrain array?
My code creates tiles of terrains on start, I wanna use SetNeighbors to connect each Instantiated terrain to its neighbors. here is my code:
var terrainMember:Transform; var terrainRow:int=20; var terrainCol:int=20; private var terrainTile:Terrain[] = new Terrain[400]; function Start () {
for (var row=1;row<terrainRow;row++){
var newRow = 100*(row-1);
for(var col=1;col<terrainCol;col++){
var arrayPosition = col-1+(terrainRow*(row-1));
var newCol=100*(col-1);
terrainTile[arrayPosition] = Instantiate(terrainMember,Vector3(newRow,0,newCol),Quaternion.identity);
}
}
}
The problem is on start it only creates one terrain and gives me an error: "Cannot cast from source type to destination type."
I need to have this array so that i can easily assign each terrain its neighbors. Otherwise I tried doing the same thing using a transform array and it just works fine. Any clue? thanks,
Did anybody have a good solution for this? I'm interested in knowing as well.
Answer by Slem · Oct 07, 2010 at 12:27 PM
Thats because the terrainTile array expects a "Terrain", but gets an "object". Just cast the Instantiated oject to Terrain like this: (Terrain)Instantiate(terrainMember....
Answer by Houndie · Dec 07, 2010 at 02:51 AM
Getting the same issue even with casting the instantiated as terrain.
Your answer
Follow this Question
Related Questions
best tile size for terrain? 2 Answers
Tiled terrains - where to put, when to load? 0 Answers
Tile generation problem 1 Answer
How to combine all meshes in an array (JAVASCRIPT) 0 Answers