- Home /
Solved..
How to calculate the length of a plane in screen size??
Hi, i am having problems getting the length of a plane.I am getting the center of the plane via Camera.main.WorldToScreenPoint(plane.position) but cannot find a way of getting the length of one size of the plane.How would i get the bounds of this plane?Could anyone help me pls?
Is the plane parallel to the camera or rotated at odd angles with respect to the camera?
it always face to the camera :) I use it as a gui texture.And the reason why i am using a 3d object is because of i don't want to code the gui to scale depending on different screen sizes.
You should post the answer so that others can benefit from it as well.
Answer by ozturkcompany · Dec 25, 2013 at 12:00 PM
The answers is the following;
var min : Vector2;
var max : Vector2;
var distanceInPixels : float;
var target : Transform;
function Start ()
{
min = Camera.main.WorldToScreenPoint(target.renderer.bounds.min);
max = Camera.main.WorldToScreenPoint(target.renderer.bounds.max);
distanceInPixels = Vector2.Distance(min, max)/2;
//distanceInPixels is the radius of the target.
//You get the radius so calculate the rest..
}
NOTE: The target must have zero rotation at Start for this to work, because bounds is an AABB (Axis Aligned Bounding Box).
your avatar is awesome!! Btw i am now doing it with the following ins$$anonymous$$d of renderer bounds, now its collider.bounds.Works great!
Follow this Question
Related Questions
Cutoff top and bottom of screen instead of sides when changing aspect ratio 1 Answer
Particles sized to screen, not scene? 1 Answer
Auto scaling GUI 3 Answers
Get Screen Size in Inches for iOS devices 0 Answers
Scaling a cube side by a plane length 0 Answers