- Home /
Question by
moinchdog · Jul 12, 2012 at 01:51 PM ·
gameobjectfpspickupweapons
Swapping Weapons In Game
Hey guy
I have a few scripts that allow me to pickup weapons in my FPS game
weaponLockout.js is attached to the locked weapon as a child of the weapons changer.
#pragma strict
var isLocked : boolean = true;
var weaponPickup : GameObject;
var playerWeapons : GameObject;
private var pickupTransform : Transform;
function Start () {
pickupTransform = weaponPickup.transform;
}
function Update () {
if(weaponPickup.GetComponent(WPickup).pickedUp == true) {
isLocked = false;
}
if(Input.GetButtonDown("Drop Weapon")) {
isLocked = true;
Drop();
}
}
function Unlock () {
isLocked = false;
}
function Drop () {
playerWeapons.SendMessage("Select2");
isLocked = true;
yield WaitForSeconds(1);
weaponPickup.gameObject.SetActiveRecursively(true);
pickupTransform.position = playerWeapons.transform.position;
}
WPickup.js is attached to the pickup and unlocks the locked weapon.
#pragma strict
var lock : weaponLockout;
var playerWeapons : GameObject;
var pickedUp : boolean = false;
var whatToSelect : int = 4;
function Start () {
pickedUp = false;
}
function OnTriggerStay (col : Collider) {
if(col.gameObject.tag == "Player_1") {
if(Input.GetButtonDown("Pickup")) {
pickedUp = true;
if(whatToSelect == 1) {
playerWeapons.SendMessage("Select1");
}
if(whatToSelect == 2) {
playerWeapons.SendMessage("Select2");
}
if(whatToSelect == 3) {
playerWeapons.SendMessage("Select3");
}
if(whatToSelect == 4) {
playerWeapons.SendMessage("Select4");
}
lock.Unlock();
gameObject.SetActiveRecursively(false);
}
}
}
i can pickup up the weapons fine but i want to be able to swap one of the current weapons for one of the pickups
I am unsure how to do this
Please help
Thanks Dj
Comment