Shooting Bullets in VR

Rushil Reddy

In this tutorial series we will be creating a room scale zombie shooter. To make it easier for you we have a starter scene with some basic assets imported.

Download Project

To start open up the inspector panel for the zombie. Go to Tag> click on Untagged> Add Tag. Click the + and Change tag 0 to “Zombie”. Now go back to the inspector and change the tag from none to Zombie and click apply to save the changes.

Now click on the Bullet prefab that is already in our scene. Go to Add Component->Script>New Script. Call it bulletManager and add these lines of code to it.

Inside the editor look for a tab called Asset Store(shown below). Once there type SteamVR Plugin into the search bar.

Component->Script>New Script. Call it bulletManager and add these lines of code to it.

void OnTriggerEnter(Collider co) {

     if(co.tag == "Zombie") {

     Destroy(gameObject);

}

}

With this we are checking to see if the bullet hits any colliders that we have set up. If it hits a zombie, then we want to call a function in our zombieController script called decrease which keeps track of that zombies health.

Now when we press play if we shoot a zombie 3 times he will die.

Restart Unity