- Home /
Question by
chrisall76 · Aug 28, 2012 at 05:37 AM ·
gunlockselect
Script ignoring variable?
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;
}
Comment
Best Answer
Answer by Dasherz · Aug 29, 2012 at 10:18 AM
make a new boolean called isShooting. if its true then you cant swap guns, if false then you can. that seems like the easiest way to me.
Your answer
Follow this Question
Related Questions
Importing Giant C4D Animation.. 0 Answers
Get a gun off a wall 1 Answer
Quaternion.Lerp messing up after being deactived and then activated again 1 Answer
Aiming down gun scope 1 Answer
When Gui Text Clicked, Quit Game 2 Answers