Hello programmers!!
I am currently making a game and I use spherecast to detect if an object is visible to the camera.
I firstly used Raycast but you needed to look at the exact center of the object to output a result.
Now my spherecast is working good but not for all resolutions.I mean the radius stays the same
but the resolution of the screen might be different and the spherecast will not work properly
var hit : RaycastHit;
var rayOrigin : Ray = Camera.main.ScreenPointToRay(Vector3( Screen.width * 0.5, Screen.height * 0.5, 0));
var sphereRadius : float = 9.0;
if (Physics.SphereCast (rayOrigin, sphereRadius, hit, 200)) {
if(hit.collider.gameObject.name == "Object561"){
Debug.Log("Hitted collider");
}
}
Is there anyway to make a cast work for all screen resolutions?!
SOLVED :
Use : renderer.isVisible
and it will work as camera sees it