I have this code:
GameObject cubexp = Instantiate(cubeShat, transform.position, transform.rotation);
Rigidbody CubeEXP = cubexp.GetComponentInChildren<Rigidbody>();
CubeEXP.AddForce(transform.forward * 5000);
It doesn’t work…or at least is not adding force to the children.
What am I doing wrong?
I got it to work like this.
GameObject cubexp = Instantiate(cubeShat, transform.position, transform.rotation);
Transform[] CubeEXP = cubexp.transform.GetComponentsInChildren<Transform>();
foreach (Transform instance in cubexp.transform.GetComponentsInChildren<Transform>())
{
Rigidbody cubRB = instance.GetComponent<Rigidbody>();
cubRB.AddForce(transform.forward * 2000);
}