Hi there I am planning on having around 15 different guns within my game and am wondering how to change weapons from the one in my hand to a weapon on the ground. I have a firing/ammo script for my guns and I have a gun swapping script that I made:
var MyHand : Transform; //your hand
var MyGun : Transform; //what your picking up
var ThatGun : Transform;
var dist = 5; //distance at which you can pick things up
private var isHolding = false;
function Update () {
if(Input.GetKeyDown(KeyCode.Q)){
if(Vector3.Distance(transform.position, MyGun.position) < dist)
{
isHolding = !isHolding;
}
}
if(isHolding == true){
MyHand.transform.DetachChildren();
MyGun.rigidbody.useGravity = false;
MyGun.parent = MyHand;
MyGun.transform.position = MyHand.transform.position;
MyGun.transform.rotation = MyHand.transform.rotation;
}
else{
MyHand.transform.DetachChildren();
MyGun.rigidbody.useGravity = true;
ThatGun.parent = MyHand;
ThatGun.transform.position = MyHand.transform.position;
ThatGun.transform.rotation = MyHand.transform.rotation;
}
}
the problem is that this script that I made-up only works for two guns and I need to swap between around 15 eventually. I know I could extend this script to work for more guns but I'm worried it would get very complicated and slow functioning.
Any help would be much appreciated
Thanks, Scribe (javascript please)