Hi,
I want to be able to destroy the instantiated children attached to a GameObject when the mouse is pressed, but I get an error. Here is the code:
var cubePrefab : GameObject;
var lineLength : float;
var numberOfCubes : int;
function Start() {
var cubeStep : float = lineLength/numberOfCubes;
for(var i = 0; i < numberOfCubes; i++) {
var newCube : GameObject;
newCube = Instantiate (cubePrefab, Vector3(i * cubeStep,0,0), Quaternion.identity);
newCube.transform.parent = transform;
}
}
function Update() {
if(Input.GetMouseButtonDown(0)){
KillChildren();
}
}
function KillChildren () {
for(var child : GameObject in transform){
Destroy(child);
}
}
The line:
for(var child : GameObject in transform){
returns the error code: InvalidCastException: Cannot cast from source type to destination type.
Anyone know why?
Thanks
S