O'Reilly logo

Developing AR Games for iOS and Android by Dominic Cushnan, Hassan EL Habbak

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

Scripting the ball gun

We have already created the projectile for the gun, and we also created the sound source for it, but we are yet to make this act like a ball gun; this is when scripting comes in handy.

The first thing we need to do is to create a prefab for the projectile we created. This is to be able to clone the projectile through the script and fire it at the poor moles. To do that, simply create a folder in the Assets folder, and name it Prefabs. Drag-and-drop the Ball object from the Hierarchy panel to the folder you just created. Now we have a prefab that we can call upon through code and can create as many balls as we want.

The ball we have attached to the camera is meaningless, because we will be creating the projectiles through code. ...

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