How would I go about Initiating a ray cast from the center of the screen (camera). Right now I am initiating from the mouses position:
function Update () {
var ray = Camera.main.ScreenPointToRay (Input.mousePosition);
var hit : RaycastHit;
if(Physics.Raycast (ray, hit, 500))
Debug.DrawLine (ray.origin, hit.point);
var objectTouching = hit.collider.name;
print(objectTouching);
currentObjectOver = hit.collider.gameObject;
}
var ray : Ray = Camera.main.ViewportPointToRay (Vector3(0.5,0.5,0));
var hit : RaycastHit;
Physics.Raycast (ray, hit);
Vector3(0.5,0.5,0) uses x = 0.5 and y = 0.5 because Viewport vectors are normalized(which means they take value from 0 to 1). So, it will be the middle of camera viewport.