O'Reilly logo

Virtual Reality Blueprints by John Williamson, Charles Palmer

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Shoot function

The Shoot () function, defined in the previous code block, runs for any frame where the Fire1 button has been pressed. The functions purpose is to simulate the Player shooting a weapon at a zombie. Instead of a projectile, we are instantiating a graphic Raycaster.

In the script you will notice that a ray called hit is created. This ray will be used to determine the trajectory of an imaginary bullet when the Fire1 button is released. The ray is drawn in the forward direction starting from the OVRCameraRig's current position. If the ray intersects with a collider attached to a zombie prefab, then a hit is recorded and the zombie dies.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required