how would I make my gun locked and then unlocked when I collide with an object. I have my weapon switch script done but I don’t know how I would make it so the player cant use it until they collide with an object.
here is my weapon switch script it is done in Java script
private var RifleEquip = true;
function Start ()
{
SelectWeapon(0);
}
function OnGUI() {
// if (GUI.RepeatButton (Rect (85,Screen.height - 80,75,75),
"Shoot")) {
// BroadcastMessage("Fire");
// }
if (RifleEquip==true) {
if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
SelectWeapon(1);
RifleEquip = false;
}
}
if (RifleEquip==false) {
if (GUI.Button (Rect (Screen.width - 210,5,50,75), " ")) {
SelectWeapon(0);
RifleEquip = true;
}
}
}
function SelectWeapon (index : int) {
for (var i=0;i<transform.childCount;i++) {
if (i == index)
transform.GetChild(i).gameObject.SetActiveRecursively(true);
else
transform.GetChild(i).gameObject.SetActiveRecursively(false);
}
}