Shooting with 3 Different Ammo
3 Bullets (these must be a prefab with a Rigidbody… refer to recent shooting tutorials for details on how to make these)
an empty game object (this will be your GUI object)
An Object to Pick Up(you should only have one of these until step 7)
Particle System(this will replace your object with an effect/other object when collected).
Make sure that your bullets are prefabs with a rigidbody.
Make sure IsTrigger is checked for your bullets and ammo.
Make sure your player is tagged as Player.
3). The scripts - there are three different scripts for this tutorial… MAKE THE FILES THE SAME NAME AS IT'S SPELLED, otherwise this WILL NOT WORK. Caps matter.
Reminder: You will get an error till all the scripts are in!
var keyReplacement: GameObject;
var GUIScript:tripleShotGUI;
var bulletScript : tripleShot;
function OnTriggerEnter (other : Collider) {
if(other.gameObject.tag == "Player"){
bulletScript.numOfBullets1+=ammoValue;
bulletScript.numOfBullets2+=ammoValue;
bulletScript.numOfBullets3+=ammoValue;
//make the replacement variable show up
var makeKeyReplacement : GameObject;
makeKeyReplacement = Instantiate(keyReplacement, transform.position, transform.rotation);
//destroy the key and replace it with sparks
if(Input.GetButtonDown("Fire1")){
//make bullet clone and set it to whatever it’s on
//make bullet clone and set it to whatever it’s on
clone = Instantiate(bullet1, transform.position,transform.rotation);
//give the clone a velocity
clone.velocity = transform.TransformDirection(Vector3.forward*50);
//Get rid of the bullet by putting the bullet destroy script on the prefab
if(Input.GetButtonDown("Fire2")){
//make bullet clone and set it to whatever it’s on
//make bullet clone and set it to whatever it’s on
clone2 = Instantiate(bullet2, transform.position,transform.rotation);
//give the clone a velocity
clone2.velocity = transform.TransformDirection(Vector3.forward*50);
//Get rid of the bullet by putting the bullet destroy script on the prefab
if(Input.GetButtonDown("Fire3")){
//make bullet clone and set it to whatever it’s on
//make bullet clone and set it to whatever it’s on
clone3 = Instantiate(bullet3, transform.position,transform.rotation);
//give the clone a velocity
clone3.velocity = transform.TransformDirection(Vector3.forward*50);
//Get rid of the bullet by putting the bullet destroy script on the prefab
the “tripleShotGUI” script:
var bulletScript : tripleShot;
GUI.Box (Rect (10,10,100,25), "Bullets1: " + bulletScript.numOfBullets1.ToString());
GUI.Box (Rect (10,45,100,25), "Bullets2: " + bulletScript.numOfBullets2.ToString());
GUI.Box (Rect (10,80,100,25), "Bullets3: " + bulletScript.numOfBullets3.ToString());
theGUI script goes into your empty game object.
bulletShooter script goes into the main camera INSIDE your character controller.
ammo script goes into your ammo object.
5). Filling in the needed objects for each script:
Drag the main camera inside the character controller into the empty slot for theGUI script.
Drag the particle, the empty game object (your GUI) and the main camera into the ammo script’s empty spots.
Drag your bullets into the bulletShooter script on your main camera.
6). Change the Num of Bullets variable in your main camera to the number of ammo you want at the start, and change the ammo value on your ammo to change how much ammo you get from each ammo pack.
7). You can now copy your ammo as many times as you want.