Weapon shooting and switching script (Javascript)

Hi, everyone! :smile:

I just wanted to add to the pool some code that could make someone’s life a little easier; since I got so much information from these forums over the years. This script is for weapon switching with the mouse scroll wheel, and hot-keys 1-4. It was wrote some more could easier be added to it. It has stats for the weapons, and a fully functional reload system with hot-key “r”.

I wrote added some OnGUI code to display the current amount and current ammo in the magazine; along with the weapon selected. The only problem with the script is that the shotgun does not have random spread coded in yet, but it still works. It should be commented enough so that it is easy for any one to follow and change where they see fit.

I will update later when i finish the Shotgun spread. Oh and the rifle is setup up to be automatic, while everything else is semi-auto (Per click; according to the fire rate for each weapon).

Updated: Fixed a bug; and added some Shotgun random spread (only on the z axis, though).

//PreFabs--------------------------------------------------------------
var bullet : GameObject;
var shotgun: GameObject;
var rocket: GameObject;
private var bulletSpawnPoint: GameObject;

//Misc-----------------------------------------------------------------
var AttackTimer : float;
var waitingForReload: float;
var shootDirection: Vector3;
var currentWeapon: int;
var previousWeapon: int;

//Booleans--------------------------------------------------------------
var weaponSwitched: boolean;
var isReloading: boolean;
var weaponSetup: boolean;
var hasPistol: boolean;
var hasRifle: boolean;
var hasShotgun: boolean;
var hasRocket: boolean;

//Weapon Reload Times; lower means faster--------------------------------
private var pistolReloadTime:float = 1.5f;
private var rifleReloadTime:float = 3f;
private var shotgunReloadTime:float = 3f;
private var rocketReloadTime:float = 5f;
private var reloadTimer: float; //Container for current Max Ammo

//Weapon Fire Rates; lower is faster-------------------------------------
private var pistolFireRate:float = .25f;
private var rifleFireRate:float = .1f;
private var shotgunFireRate:float = .5f;
private var rocketFireRate: float = 0;
private var fireRate : float; //Container for current Max Ammo

//Weapon Max Clip size---------------------------------------------------
private var maxPistolClipSize: int = 8;
private var maxRifleClipSize: int = 30;
private var maxShotgunClipSize: int = 6;
private var maxRocketClipSize: int = 1;
private var maxClipSize: int; //Container for current Max Clip size
private var pistolCurrentInClip: int;
private var rifleCurrentInClip: int;
private var shotgunCurrentInClip: int;
private var rocketCurrentInClip: int;
var currentInClip: int; //Container for ammo in clip; will go to GameController

//Weapon Max  Current Ammo----------------------------------------------
private var maxPistolAmmo: int = 80;
private var maxRifleAmmo: int = 330;
private var maxShotgunAmmo: int = 30;
private var maxRocketAmmo: int = 5;
private var currentPistolAmmo: int;
private var currentRifleAmmo: int;
private var currentShotgunAmmo: int;
private var currentRocketAmmo: int;
var currentAmmo:int;//Container for current Ammo; will go to GameController

//Weapon Damage-----------------------------------------------------------
private var pistolDamage: int = 5;
private var rifleDamage: int = 3;
private var shotgunDamage: int = 7;
private var rocketDamage: int = 15;
static var weaponDamage: int; //Container for current weapon damage

//Bullet Speed------------------------------------------------------------
private var pistolBulletSpeed: float = 15;
private var rifleBulletSpeed: float = 20;
private var shotgunBulletSpeed: float = 15;
private var rocketBulletSpeed: float = 10;
static var bulletSpeed: float; //Container for current bullet speed

function Start()
{
	//Get bullet spawn point
	bulletSpawnPoint = GameObject.Find("BulletSpawnPoint");
	
	//Temp seetings for testing, CHANGE LATER!!!!
	hasPistol = true;
	hasRifle = true;
	hasShotgun = true;
	hasRocket = true;
	
	//Setup current and previous weapon
	weaponSetup = false; // for first time setup
	isReloading = false;
	weaponSwitched = false;
	currentWeapon = 0; // for first time setup
	currentPistolAmmo = maxPistolAmmo;
	currentRifleAmmo = maxRifleAmmo;
	currentShotgunAmmo = maxShotgunAmmo;
	currentRocketAmmo = maxRocketAmmo;
	pistolCurrentInClip = maxPistolClipSize;
	rifleCurrentInClip = maxRifleClipSize;
	shotgunCurrentInClip = maxShotgunClipSize;
	rocketCurrentInClip = maxRocketClipSize;
}
function Update () 
{
	//First time setup, runs once.
	if(!weaponSetup)
	{
		GetCurrentWeapon(currentWeapon);
		weaponSetup = true;
	}
	
	//Change weapon with Mouse wheel
	if(Input.GetAxis("Mouse ScrollWheel") > 0)//MouseWheel button up
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		if(currentWeapon == 3)
		{
			currentWeapon = 0;
		}
			else
			{
				currentWeapon++;
			}
	}
	else if (Input.GetAxis("Mouse ScrollWheel") < 0)//Mouse Wheel down
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		if(currentWeapon == 0)
		{
			currentWeapon = 3;
		}
			else
			{
				currentWeapon--;
			}
	}
	
	//Change weapons with Numbers directly; 1-4.
	if(Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)  hasPistol)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 0;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2)  hasRifle)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 1;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3)  hasShotgun)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 2;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4)  hasRocket)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 3;
	}
	
	//Input for Reload
	if(Input.GetButtonDown("Reload")  currentAmmo > 0  currentInClip != maxClipSize)
	{Debug.Log("test4");
		Reload();
	}
	
	//Did we switch weapons, if so save weapon stats
	if(weaponSwitched)
	{
		SaveCurrentWeaponsStats(previousWeapon);
		GetCurrentWeapon(currentWeapon); //What is the current weapon selected?
		weaponSwitched = false;
	}
		
	//if can fire, fire. Check for reloading!
	if(!isReloading)
	{
		if (AttackTimer > 0)
		{
			AttackTimer -= Time.deltaTime;
		}
		
		if (AttackTimer <= 0)
		{
			if(currentWeapon == 1)
			{
				if(Input.GetButton("Fire"))//AutoFire bullets
				{
					Fire(currentWeapon);
					AttackTimer = fireRate;
					currentInClip--;
					
					if(currentInClip == 0  currentAmmo >= 1)
					{Debug.Log("test1");
						Reload();
					}
				}
			}
				else
				{
					if(Input.GetButtonDown("Fire"))//Single fire bullets per click
					{
						if(currentInClip >= 1)
						{Debug.Log("test2");
							Fire(currentWeapon);
							AttackTimer = fireRate;
							currentInClip--;
							
							if(currentInClip == 0  currentAmmo >= 1)
							{Debug.Log("test3");
								Reload();
							}
						}
					}
				}
			
		}
	}
		else
		{
			if (AttackTimer > 0)
			{Debug.Log("test5");
				AttackTimer -= Time.deltaTime;
			}
				
			waitingForReload -= Time.deltaTime;
			
			if(waitingForReload <= 0)
			{
				isReloading = false;
			}
		}
}

function GetCurrentWeapon(currentWeapon: int)
{
	Debug.Log("Change to new weapons and set stats!");
	//Setup max ammo; clip size; fire rate; damage based off of weapon
	switch (currentWeapon)
	{
		case 0://Pistol
			reloadTimer = pistolReloadTime;
			bulletSpeed = pistolBulletSpeed;
			weaponDamage = pistolDamage;
			currentAmmo = currentPistolAmmo;
			fireRate = pistolFireRate;
			maxClipSize = maxPistolClipSize;
			currentInClip = pistolCurrentInClip;
			break;
			
		case 1://Rifle
			reloadTimer = rifleReloadTime;
			bulletSpeed = rifleBulletSpeed;
			weaponDamage = rifleDamage;
			currentAmmo = currentRifleAmmo;
			fireRate = rifleFireRate;
			maxClipSize = maxRifleClipSize;
			currentInClip = rifleCurrentInClip;
			break;
			
		case 2://Shotgun
			reloadTimer = shotgunReloadTime;
			bulletSpeed = shotgunBulletSpeed;
			weaponDamage = shotgunDamage;
			currentAmmo = currentShotgunAmmo;
			fireRate = shotgunFireRate;
			maxClipSize = maxShotgunClipSize;
			currentInClip = shotgunCurrentInClip;
			break;
			
		case 3://Rocket
			reloadTimer = rocketReloadTime;
			bulletSpeed = rocketBulletSpeed;
			weaponDamage = rocketDamage;
			currentAmmo = currentRocketAmmo;
			fireRate = rocketFireRate;
			maxClipSize = maxRocketClipSize;
			currentInClip = rocketCurrentInClip;
			break;
			
		default:
			Debug.Log("There is no current weapon!");
			break;
	}
}

function SaveCurrentWeaponsStats(previousWeapon: int)
{
	Debug.Log("Saved current weapon stats.");
	switch (previousWeapon)
	{
		case 0://Pistol
			currentPistolAmmo = currentAmmo;
			pistolCurrentInClip = currentInClip;
			break;
			
		case 1://Rifle
			currentRifleAmmo = currentAmmo;
			rifleCurrentInClip =currentInClip;
			break;
			
		case 2://Shotgun
			currentShotgunAmmo =currentAmmo;
			shotgunCurrentInClip =currentInClip;
			break;
			
		case 3://Rocket
			currentRocketAmmo = currentAmmo;
			rocketCurrentInClip = currentInClip;
			break;
			
		default:
			Debug.Log("There was no previous weapon!");
			break;
	}
}

function Fire(currentWeapon: int)
{
	Debug.Log("Fired something");
	switch (currentWeapon)
	{
		case 0://Pistol, this is good.
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(bullet, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));	
			break;
			
		case 1://Rifle, might be ok.
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(bullet, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));
			break;
			
		case 2://Shotgun, increase i for more bullets and bigger spread
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection;
			for(i=0; i<6; i++)
			{
				shotgunSpread =(Vector3(0,0,i) + shootDirection).normalized;
				Instantiate(shotgun, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shotgunSpread));
			}	
			break;
			
		case 3://Rocket, need to change!!
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(rocket, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));
			break;
			
		default:
			Debug.Log("There is a problem with firing!");
			break;
	}
}

function Reload()
{
	isReloading = true;
	waitingForReload = reloadTimer;
	
	if(currentAmmo >= maxClipSize)
	{	
		var temp2: int = maxClipSize - currentInClip;
		currentAmmo -= temp2;
		currentInClip += temp2;
	}
	else
	{
		if(currentInClip + currentAmmo > maxClipSize)
		{
			var temp: int;
			temp = (currentInClip + currentAmmo) - maxClipSize;
			currentInClip = maxClipSize;
			currentAmmo = temp;
		}
		else
		{
			currentInClip += currentAmmo;
			currentAmmo = 0;
		}
	}
}

Did not look through all of it, but thanks for sharing, I might use this soon! Like the shotgun feature

Thanks I hope it helps. I still want to add some features to it. Like the ability to cancel a reload if you switch weapons. Right now it forces you to wait until that reload is done. Which i guess could be a mechanic? But i going to change it and update the script anyway.

Here is the updated code with the ability to cancel reloads. I guess there isn’t much left with this script except maybe to change some weapon stats to global variables so a StoreManager script can change the values with “Upgrades” for the weapons. But that’s quite simple, so hope this helps someone. I’m out!:sunglasses:

Just updated this again. Added some check if the player doesn’t have the weapons. The changes affect the mouse wheel. Just can the boolean to give the player a weapon. By default they are all enabled for testing.

//PreFabs--------------------------------------------------------------
var bullet : GameObject;
var shotgun: GameObject;
var rocket: GameObject;
private var bulletSpawnPoint: GameObject;

//Misc-----------------------------------------------------------------
var AttackTimer : float;
var waitingForReload: float;
var shootDirection: Vector3;
var currentWeapon: int;
var previousWeapon: int;

//Booleans--------------------------------------------------------------
var weaponSwitched: boolean;
var canceledReload:boolean;
var isReloading: boolean;
var weaponSetup: boolean;
var hasPistol: boolean;
var hasRifle: boolean;
var hasShotgun: boolean;
var hasRocket: boolean;

//Weapon Reload Times; lower means faster--------------------------------
private var pistolReloadTime:float = 1.5f;
private var rifleReloadTime:float = 3f;
private var shotgunReloadTime:float = 3f;
private var rocketReloadTime:float = 5f;
private var reloadTimer: float; //Container for current Max Ammo

//Weapon Fire Rates; lower is faster-------------------------------------
private var pistolFireRate:float = .25f;
private var rifleFireRate:float = .1f;
private var shotgunFireRate:float = .5f;
private var rocketFireRate: float = 0;
private var fireRate : float; //Container for current Max Ammo

//Weapon Max Clip size---------------------------------------------------
private var maxPistolClipSize: int = 8;
private var maxRifleClipSize: int = 30;
private var maxShotgunClipSize: int = 6;
private var maxRocketClipSize: int = 1;
private var maxClipSize: int; //Container for current Max Clip size
private var pistolCurrentInClip: int;
private var rifleCurrentInClip: int;
private var shotgunCurrentInClip: int;
private var rocketCurrentInClip: int;
var currentInClip: int; //Container for ammo in clip; will go to GameController

//Weapon Max  Current Ammo----------------------------------------------
private var maxPistolAmmo: int = 80;
private var maxRifleAmmo: int = 330;
private var maxShotgunAmmo: int = 30;
private var maxRocketAmmo: int = 5;
private var currentPistolAmmo: int;
private var currentRifleAmmo: int;
private var currentShotgunAmmo: int;
private var currentRocketAmmo: int;
var currentAmmo:int;//Container for current Ammo; will go to GameController

//Weapon Damage-----------------------------------------------------------
private var pistolDamage: int = 5;
private var rifleDamage: int = 3;
private var shotgunDamage: int = 7;
private var rocketDamage: int = 15;
static var weaponDamage: int; //Container for current weapon damage

//Bullet Speed------------------------------------------------------------
private var pistolBulletSpeed: float = 15;
private var rifleBulletSpeed: float = 20;
private var shotgunBulletSpeed: float = 15;
private var rocketBulletSpeed: float = 10;
static var bulletSpeed: float; //Container for current bullet speed

function Start()
{
	//Get bullet spawn point
	bulletSpawnPoint = GameObject.Find("BulletSpawnPoint");
	
	//Temp seetings for testing, CHANGE LATER!!!!
	hasPistol = true;
	hasRifle = true;
	hasShotgun = true;
	hasRocket = true;
	
	//Setup current and previous weapon
	weaponSetup = false; // for first time setup
	isReloading = false;
	weaponSwitched = false;
	currentWeapon = 0; // for first time setup
	currentPistolAmmo = maxPistolAmmo;
	currentRifleAmmo = maxRifleAmmo;
	currentShotgunAmmo = maxShotgunAmmo;
	currentRocketAmmo = maxRocketAmmo;
	pistolCurrentInClip = maxPistolClipSize;
	rifleCurrentInClip = maxRifleClipSize;
	shotgunCurrentInClip = maxShotgunClipSize;
	rocketCurrentInClip = maxRocketClipSize;
}
function Update () 
{
	//First time setup, runs once.
	if(!weaponSetup)
	{
		GetCurrentWeapon(currentWeapon);
		weaponSetup = true;
	}
	
	//Change weapon with Mouse wheel
	if(Input.GetAxis("Mouse ScrollWheel") > 0)//MouseWheel button up
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		if(currentWeapon == 3)
		{
			currentWeapon = 0;
		}
			else
			{
				currentWeapon++;
				//Check to see if player has other weapons; if not skip that weapon with the scroll
				if(currentWeapon == 1  !hasRifle)
				{
					currentWeapon++;
				}
				else if (currentWeapon == 2  !hasShotgun)
				{
					currentWeapon++
				}
				else if(currentWeapon == 3  !hasRocket)
				{
					currentWeapon = 0;
				}
				
				
			}
	}
	else if (Input.GetAxis("Mouse ScrollWheel") < 0)//Mouse Wheel down
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		if(currentWeapon == 0)//This check is important because we start with the pistol unlike above^^
		{
			currentWeapon = 3;//This should be the highest weapon; for me its the four one.
			if(!hasRocket)//Check if player has this; then set back and check all over weapons until player has it.
			{
				currentWeapon--;
				if(!hasShotgun)
				{
					currentWeapon--;
					if(!hasRifle)
					{
						currentWeapon = 0;
					}
					
				}
				
			}
			
		}
			else
			{
				currentWeapon--;
				if(currentWeapon == 1  !hasRifle)
				{
					currentWeapon--;
				}
				else if (currentWeapon == 2  !hasShotgun)
				{
					currentWeapon--
				}
				else if(currentWeapon == 3  !hasRocket)
				{
					currentWeapon = 0;
				}
			}
	}
	
	//Change weapons with Numbers directly; 1-4.
	if(Input.GetKeyDown(KeyCode.Alpha1) || Input.GetKeyDown(KeyCode.Keypad1)  hasPistol)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 0;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha2) || Input.GetKeyDown(KeyCode.Keypad2)  hasRifle)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 1;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha3) || Input.GetKeyDown(KeyCode.Keypad3)  hasShotgun)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 2;
	}
	else if (Input.GetKeyDown(KeyCode.Alpha4) || Input.GetKeyDown(KeyCode.Keypad4)  hasRocket)
	{
		previousWeapon = currentWeapon;
		weaponSwitched = true;
		currentWeapon = 3;
	}
	
	//Input for Reload
	if(Input.GetButtonDown("Reload")  currentAmmo > 0  currentInClip != maxClipSize)
	{Debug.Log("Reload Manual");
		Reload();
	}
	
	//Did we switch weapons, if so save weapon stats
	if(weaponSwitched)
	{
		SaveCurrentWeaponsStats(previousWeapon);
		GetCurrentWeapon(currentWeapon); //What is the current weapon selected?
		weaponSwitched = false;
		
		if(isReloading)
		{
			canceledReload = true;
		}
	}
		
	//if can fire, fire. Check for reloading!
	if(!isReloading)
	{
		if (AttackTimer > 0)
		{
			AttackTimer -= Time.deltaTime;
		}
		
		if (AttackTimer <= 0)
		{
			if(currentWeapon == 1)
			{
				if(Input.GetButton("Fire"))//AutoFire bullets
				{Debug.Log("Firing Rifle!");
					Fire(currentWeapon);
					AttackTimer = fireRate;
					currentInClip--;
					
					if(currentInClip == 0  currentAmmo >= 1)
					{Debug.Log("Empty Rifle; Reload");
						Reload();
					}
				}
			}
				else
				{
					if(Input.GetButtonDown("Fire"))//Single fire bullets per click
					{
						if(currentInClip >= 1)
						{Debug.Log("Firing Weapon!");
							Fire(currentWeapon);
							AttackTimer = fireRate;
							currentInClip--;
							
							if(currentInClip == 0  currentAmmo >= 1)//AutoReload at Zero
							{Debug.Log("Empty Weapon; auto reload");
								Reload();
							}
						}
						else if(currentInClip == 0  currentAmmo >= 1)//If you canceled a reload but now fire without Ammo; Force reload
						{Debug.Log("Empty Weapon; Force reload");
							Reload();
						}
					}
				}
			
		}
	}
		else
		{
			if (AttackTimer > 0)
			{Debug.Log("test5");
				AttackTimer -= Time.deltaTime;
			}
			
				if(!canceledReload)
				{
					waitingForReload -= Time.deltaTime;
					Debug.Log("Waiting for time to stop");
					if(waitingForReload <= 0)
					{Debug.Log("Can reload now; should be done!");
						 //wait till finished to refill clips
						if(currentAmmo >= maxClipSize)
						{	Debug.Log("Reload is broke here");
							var temp2: int = maxClipSize - currentInClip;
							currentAmmo -= temp2;
							currentInClip += temp2;
						}
						else
						{
							if(currentInClip + currentAmmo > maxClipSize)
							{
								var temp: int;
								temp = (currentInClip + currentAmmo) - maxClipSize;
								currentInClip = maxClipSize;
								currentAmmo = temp;
							}
							else
							{
								currentInClip += currentAmmo;
								currentAmmo = 0;
							}
						}
						isReloading = false;
					}
				}
				else
				{Debug.Log("Reload was canceled");
					waitingForReload = 0;
					isReloading = false;
				}	
				
			
		}
}

function GetCurrentWeapon(currentWeapon: int)
{
	Debug.Log("Change to new weapons and set stats!");
	//Setup max ammo; clip size; fire rate; damage based off of weapon
	switch (currentWeapon)
	{
		case 0://Pistol
			reloadTimer = pistolReloadTime;
			bulletSpeed = pistolBulletSpeed;
			weaponDamage = pistolDamage;
			currentAmmo = currentPistolAmmo;
			fireRate = pistolFireRate;
			maxClipSize = maxPistolClipSize;
			currentInClip = pistolCurrentInClip;
			break;
			
		case 1://Rifle
			reloadTimer = rifleReloadTime;
			bulletSpeed = rifleBulletSpeed;
			weaponDamage = rifleDamage;
			currentAmmo = currentRifleAmmo;
			fireRate = rifleFireRate;
			maxClipSize = maxRifleClipSize;
			currentInClip = rifleCurrentInClip;
			break;
			
		case 2://Shotgun
			reloadTimer = shotgunReloadTime;
			bulletSpeed = shotgunBulletSpeed;
			weaponDamage = shotgunDamage;
			currentAmmo = currentShotgunAmmo;
			fireRate = shotgunFireRate;
			maxClipSize = maxShotgunClipSize;
			currentInClip = shotgunCurrentInClip;
			break;
			
		case 3://Rocket
			reloadTimer = rocketReloadTime;
			bulletSpeed = rocketBulletSpeed;
			weaponDamage = rocketDamage;
			currentAmmo = currentRocketAmmo;
			fireRate = rocketFireRate;
			maxClipSize = maxRocketClipSize;
			currentInClip = rocketCurrentInClip;
			break;
			
		default:
			Debug.Log("There is no current weapon!");
			break;
	}
}

function SaveCurrentWeaponsStats(previousWeapon: int)
{
	Debug.Log("Saved current weapon stats.");
	switch (previousWeapon)
	{
		case 0://Pistol
			currentPistolAmmo = currentAmmo;
			pistolCurrentInClip = currentInClip;
			break;
			
		case 1://Rifle
			currentRifleAmmo = currentAmmo;
			rifleCurrentInClip =currentInClip;
			break;
			
		case 2://Shotgun
			currentShotgunAmmo =currentAmmo;
			shotgunCurrentInClip =currentInClip;
			break;
			
		case 3://Rocket
			currentRocketAmmo = currentAmmo;
			rocketCurrentInClip = currentInClip;
			break;
			
		default:
			Debug.Log("There was no previous weapon!");
			break;
	}
}

function Fire(currentWeapon: int)
{
	Debug.Log("Fired something");
	switch (currentWeapon)
	{
		case 0://Pistol, this is good.
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(bullet, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));	
			break;
			
		case 1://Rifle, might be ok.
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(bullet, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));
			break;
			
		case 2://Shotgun, increase i for more bullets and bigger spread
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection;
			for(i=0; i<6; i++)
			{
				shotgunSpread =(Vector3(0,0,i) + shootDirection).normalized;
				Instantiate(shotgun, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shotgunSpread));
			}	
			break;
			
		case 3://Rocket, need to change!!
			shootDirection = gameObject.GetComponent("PlayerMoveController").motor.facingDirection.normalized;	
			Instantiate(rocket, bulletSpawnPoint.transform.position, Quaternion.LookRotation(shootDirection));
			break;
			
		default:
			Debug.Log("There is a problem with firing!");
			break;
	}
}

function Reload()
{
	Debug.Log("In reload function");
	canceledReload = false;
	isReloading = true;
	waitingForReload = reloadTimer;
}