It all happened when I declared the camera as global of type transform. Just wanted the debug ray to follow head movement and to be placed at the center. I managed to get that but all objects in the scene just followed suit
public GameObject ground;
public Transform lookCamera;
void Update()
{
Transform camera = lookCamera;
Ray Ray;
RaycastHit[] hits;
GameObject hitObject;
Debug.DrawRay(camera.position,camera.rotation * Vector3.forward * 100.0f)
ray = new Ray(camera.position, camera.rotation * Vector3.forward);
hits = Physics.Raycast(ray);
for (int i=0; i<hits.Length; i++)
{
RaycastHit hit = hits[i];
hitObject = hit.collider.gameObject;
if (hitObject == ground)
{
Debug Log("Hit (x,y,z): " + hit.point.toString("F2"));
transform.position = hit.point;
}
}
}
}
Now I've removed the global declaration and change from this
Transform camera = lookCamera;
To this
Transform camera = Camera.main.transform;
The problem never solved. I even created a fresh new scene. Check the bindings on XRRig main camera seem nothing could help. Do anybody got any idea how to solve this?