I need to make a script where it only switches weapons, but it’s ignoring the variable
that locks the weapon switching if your shooting. Any help?
Weapon Changing Script:
var SelectedWeapon : GameObject;
var Primary : GameObject;
var Secondary : GameObject;
var Melee : GameObject;
var PrimaryLock = Primary.GetComponent(WeaponLock);
var SecondaryLock = Secondary.GetComponent(WeaponLock);
var MeleeLock = Melee.GetComponent(WeaponLock);
function Start () {
SelectedWeapon = Primary; //Selects Primary weapon
}
function Update () {
if(Input.GetKey(KeyCode.Alpha1) && (SecondaryLock.isLocked == false) || Input.GetKey(KeyCode.Alpha1) && (MeleeLock.isLocked == false)){
SelectedWeapon = Primary;
}
if(Input.GetKey(KeyCode.Alpha2) && (SecondaryLock.isLocked == false) || Input.GetKey(KeyCode.Alpha2) && (MeleeLock.isLocked == false)){
SelectedWeapon = Secondary;
}
if(Input.GetKey(KeyCode.Alpha3) && (SecondaryLock.isLocked == false) || Input.GetKey(KeyCode.Alpha3) && (PrimaryLock.isLocked == false)){
SelectedWeapon = Melee;
}
if(SelectedWeapon == Primary){
Primary.SetActiveRecursively(true);
Secondary.SetActiveRecursively(false);
Melee.SetActiveRecursively(false);
}
if(SelectedWeapon == Secondary){
Primary.SetActiveRecursively(false);
Secondary.SetActiveRecursively(true);
Melee.SetActiveRecursively(false);
}
if(SelectedWeapon == Melee){
Primary.SetActiveRecursively(false);
Secondary.SetActiveRecursively(false);
Melee.SetActiveRecursively(true);
}
}
Lock Script:
var isLocked : boolean;
var ThisGun : GameObject;
function Start () {
}
function Update () {
}
function Lock(){
isLocked = true;
}
function Unlock(){
isLocked = false;
}