I created a new VR project. The application works fine when I attach vr_camera.js to the main camera. However when the code is attached to any entity(a cube in my case), I see a black screen. Would be great to know the solution for this.
The WebVR library also includes a file called vr_camera.js. This should be attached to an Entity that will behave as your camera. This Entity could already have a camera component attached (though that is not required). The VrCamera script will create a pair of cameras (one for each eye!) when VR mode is activated and disable the existing camera component.
There is a bug in vr_camera.js which aborts presenting if there is not a camera on the script entity. I’ve fixed this in the starter kit. You can fix this in your project. On line 158 of vr_camera.js
The line:
self.entity.camera.enabled = false;
Should be:
if (self.entity.camera) {
self.entity.camera.enabled = false;
}
If you don’t have an enabled camera in the scene then you will see a black screen until you enable the vr camera script (which enables new cameras). Usually you would need a non-VR camera to use until VR is activated.