I have a script
but the script is for when I walk over to my gun and the gui pops up, how do i get rid of the gui by either pressing 2 or walking away
var message = false;
function OnTriggerEnter (other : Collider) {
message = true; }
function OnGUI () {
if (message){
GUI.Box (Rect (600, 350, 250, 40), "Press 2 to take this gun");
}
}
You could use the OnTriggerExit function and use a var for input;
private var message = false;
private var gunTaken = false; //A variable for if you have taken the gun
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 this gun");
if(Input.GetKeyDown(KeyCode.2){ //if you take the gun it is taken
gunTaken = true;
}
}
}
var message = false;
function OnTriggerEnter (other : Collider) {
if (!message){
message = true;
}
}
function OnTriggerExit (other : Collider) {
if (message){
message = false;
}
}
function OnGUI () {
if (message){
GUI.Box (Rect (600, 350, 250, 40), "Press 2 to take this gun");
}
}