- Home /
Question by
deathjam4 · Sep 10, 2015 at 06:34 PM ·
javascriptarraysintparent and child
Javascript removing children of an array list by a int
I am not he one who originally wrote this but i have been trying to get it to destroy the children it spawns for what feels like ages now to no success.
I plan to change the touch function in the future but for now this is what the function looks like. The function bellow works and spawns the object it just does not remove it. The problem code that shows is unknown identifier 'j'. if i take the array part out of hte destroy it says transform is not a variable of ... exctra says the same for all the others if i remove till it says only .gameobject
Any help is greatly appreciated. and a thanks in advance.
function Awake() {
helperIngredientDummies = GameObject.FindGameObjectsWithTag("IngredientsHolder_01")+GameObject.FindGameObjectsWithTag("IngredientsHolder_02")+GameObject.FindGameObjectsWithTag("IngredientsHolder_03")+GameObject.FindGameObjectsWithTag("IngredientsHolder_04")+GameObject.FindGameObjectsWithTag("IngredientsHolder_05")+GameObject.FindGameObjectsWithTag("IngredientsHolder_06");
}
function checkTouch(pos){
var wp : Vector3 = Camera.main.ScreenToWorldPoint(pos);
var touchPos : Vector2 = new Vector2(wp.x, wp.y);
var hit = Physics2D.OverlapPoint(touchPos);
//var childs : int = transform.childCount;
if(hit){
Destroy(helperIngredients[j].transform.parent.gameObject);
if(showProductIngredientHelpers) {
helperIngredients = new GameObject[productIngredients];
for(var j = 0; j < productIngredients; j++) {
var ingredientID : int = productIngredientsIDs[j] - 1; // Array always starts from 0, while we named our ingredients from 1.
helperIngredients[j].AddComponent = Instantiate(availableIngredients[ingredientID], helperIngredientDummies[j].transform.position, Quaternion.Euler(90, 180, 0));
helperIngredients[j].tag = "ingIcon";
helperIngredients[j].name = "helperIngredient #" + j;
helperIngredients[j].GetComponent(ProductMover).enabled = false;
helperIngredients[j].transform.parent = helperIngredients[j].transform;
}
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612033231im_/https://answers.unity.com/themes/thub/images/avi.jpg)