x


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;
}
more ▼

asked Aug 28 '12 at 05:37 AM

chrisall76 gravatar image

chrisall76
136 4 9 14

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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.

more ▼

answered Aug 29 '12 at 10:18 AM

Dasherz gravatar image

Dasherz
192 1 2 5

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x447
x125
x90

asked: Aug 28 '12 at 05:37 AM

Seen: 190 times

Last Updated: Aug 29 '12 at 10:18 AM