- Home /
weapon pickup
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);
}
}
Format your code by indenting 4 space or 1 tab before pasting or by selecting it and hitting the code button after pasting. Don't use \> to format code.
Answer by whydoidoit · Jun 28, 2012 at 10:03 PM
Do this:
Attach a rigidbody (set to isKinematic false if you don't want physics) to your character
Have a collider on your character
Have a collider set to isTrigger = true on the item you need to touch
Set the tag of the touchable item to weapon activate
Write an OnTriggerEnter function on your character and check for the touch tag. If you find it set fireable to true.
Write an OnTriggerExit function for your character and check for the touch tag and set fireable to false.
Use the fireable boolean to turn on your buttons.
do you mean to add the OnTriggerEnter function to my already existing script or to make a new script?
where would I put them
sorry for being a complete noob to progra$$anonymous$$g
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
problem with weapon animation -.- 0 Answers
How would go about making a weapon pick up? 3 Answers
Very simple picking up items script? 2 Answers