I’m very new to Unity and struggling to find the radius of a circle relative to the camera. I’m updating the localScale on update and want to find what percentage of the screen the circle is filling. Thoughts?
okay, this only works if you circle is all in the bounds of camera.
returns the percent off the circle filing,WORKS with circles… but this is not nice, sometimes the percent go up to 1, and is not very confiable
var percent : float;
function Update()
{
percent= radiusinpixels(gameObject);
}
function radiusinpixels(asteroid :GameObject)
{
var radius : Vector3;
radius.x =renderer.bounds.size.x/2;
var pixelradius: float =(Camera.main.WorldToScreenPoint(asteroid.renderer.bounds.center)- Camera.main.WorldToScreenPoint(asteroid.renderer.bounds.center+radius)).magnitude;
var pixelarea : float = Mathf.Pow(pixelradius,2)*Mathf.PI;
var screenarea : float = (Camera.main.pixelWidth)*(Camera.main.pixelHeight);
return (pixelarea/screenarea);
}