Hello,
I'm trying to calculate objects' masses based on density and volume.
Imagine I have a Box2DSprite and it is 1,1 (x,y), I could use mass=density*Box2D.localScale.x*Box2D.localScale.y and calculate it.
I want to order the boxes in a GameObject called Boxes and then they are parents.
I want to calculate **each** box weight/mass **individually** based on the formula and then apply to the objects!
How could I do this?
Code in JS:
#pragma strict
var Density:float=1000;
function Start(){
var Rigidbodies=gameObject.GetComponentsInChildren(Rigidbody2D);
var Transforms=gameObject.GetComponentsInChildren(Transform);
for (var Tfm : Transform in Transforms)
for (var Rb : Rigidbody2D in Rigidbodies)
Rb.mass=Density*Tfm.localScale.x*Tfm.localScale.y;
}
↧