FindObjectsOfType(Rigidbody);

Is there a way to find all rigidbodys that are currently in the scene?
my scripts so far:

var AllRigidbodys[] = FindObjectsOfType(Rigidbody);

… it’s not working :frowning: can someone help?

That should work - what's happening?

2 Answers

2

Remove the from after AllRigidbodys

var AllRigidbodys = FindObjectsOfType(Rigidbody);

You have an array of rigidbodies not a single one - so you need to loop over them. The array doesn't have a .gameObject - the members of the array do: for(var rb : Rigidbody in AllRigidbodys) { rb.AddExplosionForce(explosionForce); }

Can you mark the question as answered?

See you found it! Thx

Since you probably wish to define an array:

var AllRigidbodys : Rigidbody[] = GameObject.FindObjectsOfType(Rigidbody) as Rigidbody[];