- Home /
Unity FPS question
How to lock a variable in till you press a button in a collider. My scripts
function Start () { // Select the first weapon SelectWeapon(0); }
function Update () {
if (Input.GetKeyDown("1")) {
SelectWeapon(0);
}
else if (Input.GetKeyDown("2")) {
SelectWeapon(1);
}
else if (Input.GetKeyDown("3")) {
SelectWeapon(2);
}
} function SelectWeapon (index : int) { for (var i=0;iprivate var message = false; private var gunTaken = false; //A variable for if you have taken the gun private var m4a1 = true;
function OnTriggerEnter(other : Collider){ message = true; }
function OnTriggerExit(other : Collider){ //if we exit the collider we cant pick it up message = false; }
function OnGUI () { if (message && !gunTaken){ //if you haven't taken the gun GUI.Box (Rect (600, 350, 250, 40), "Press 2 to take the M4A1"); if (Input.GetKeyDown("2")) { //if you take the gun it is taken gunTaken = true; } } }`
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Accessing other script problem 1 Answer
Please tell me what is wrong with this Projectile.js file 1 Answer
Need help with WeaponSwitch Script 0 Answers
Particles are off when I shoot 1 Answer