BCE0149: The type ‘UnityEngine.GameObject’ must derive from ‘UnityEngine.Component’ in order to substitute the generic parameter ‘T’ in ‘UnityEngine.GameObject.GetComponents.()’.
with this code in unityscript :
just1Explode = Instantiate(Resources.Load("explode1"), vec, Quaternion.identity);
var gos : GameObject[];
//gos = just1Explode.GetComponents.();
gos = just1Explode.GetComponents.<GameObject>();
for (var jo : GameObject in gos) {
Debug.Log("h");
}
I have got a prefab with several gameobject inside, each with a rigidbody, and I would like to add a different impulse to each of them to create an explosion.
You are trying to get Components of type GameOject but GameObject is not a Component. I hope the following code helps. My JS is close to non-existant.
var gos : MyExplosingScript[];
gos = just1Explode.GetComponents.<MyExplosingScript>();
for (var jo : MyExplosingScript in gos) {
Debug.Log("h");
jo.StartMyAwesomeExplosion();
}
}
just1Explode = Instantiate(Resources.Load("explode1"), vec, Quaternion.identity);
var gos : Component[];
gos = just1Explode.GetComponents();
for (var jo : Component in gos) {
Debug.Log("h");
}
EDIT : I just saw that you said that just1Explode has children, so you have to loop on its children and then search the right component in them. So the right method to use should be GetComponentsInChildren()
just1Explode = Instantiate(Resources.Load("explode1"), vec, Quaternion.identity);
var gos : Component[];
gos = just1Explode.GetComponentsInChildren<YourComponent>();
for (var jo : Component in gos) {
Debug.Log("h");
}