- Home /
How to check if one object is bigger than another?
Hello, i'm just wondering if any code exists to compare the scale of one object to another?
I.E
if(Object1Size > object2Size)
{
do stuff
}
If your taking about volume then this can get quite difficult.
I'm only working in 2d space, should have mentioned this. it's answered anyway.
Answer by ritesh_khokhani · Feb 16, 2014 at 01:33 PM
Hi, use Vector3.magnitudes or Vector3.sqrMagnitude to compare two vector as shown below,
GameObject.Find("Cube1").transform.localScale.magnitude < GameObject.Find("Plane1").transform.localScale.magnitude
Thanks! any idea if i am able to check if an object i have collided with is smaller than me?
frosstt: http://docs.unity3d.com/Documentation/ScriptReference/Collider.OnCollisionEnter.html
OnCollisionEnter on a script on your GameObject should do the trick. It gets called with a Collision object, which contains transform information that you can use combined with khokhani's answer.
Also, since you're working in 2D space, those operations exist for Vector2 as well, Vector2.magnitude, Vector2.sqr$$anonymous$$agnitude.