Hello everyone,
I have stored the DestoryOnTouch.cs under “Scripts/ButtonPop_Controll/”, the DestoryOnTouch.cs used to destory the object on touch and it is work if i add the script in unity editor, not runtime.
I have added the code shown as below in a parent node object named Workstation, there are number of child object, so i using a for loop to add the DestoryOnTouch.cs in runtime
However,it is not work, anyone can help me find the problem?
Thank you.
if(mDele)
{ int childs = transform.childCount;
for (int i = childs - 1; i >= 0; i--)
{ transform.GetChild(i).gameObject.AddComponent("Scripts/ButtonPop_Control/DestoryOnTouch");
}
}
if(!mDele)
{ int childs = transform.childCount;
for (int i = childs - 1; i >= 0; i--)
{ GameObject.Destroy(transform.GetChild(i).gameObject.GetComponent("Scripts/ButtonPop_Controll/DestoryOnTouch"));
}
}