Hey, I wanted to make GUI to disappear forever after you click “E” but I don’t know how to make it. Currently, when you enter the trigger, gui appears, when you leave it hides. I want to make it so that, if you make the phone call, it disapperas for ever, even if you enter the trigger again.
var Phonecall : AudioClip;
var isInside : boolean = false;
var hasMadePhoneCall : boolean = false;
var useGui : boolean = false;
function Update()
{
if (isInside && Input.GetKeyDown(KeyCode.E) && !hasMadePhoneCall)
{
hasMadePhoneCall = true;
disableGui();
MakePhoneCall();
}
}
function MakePhoneCall()
{
audio.PlayOneShot(Phonecall);
yield WaitForSeconds(31);
Application.LoadLevel("Ending");
}
function disableGui()
{
useGui = false;
}
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
isInside = true;
useGui = true;
}
}
function OnTriggerExit (other : Collider){
if (other.gameObject.tag == "Player") {
isInside = false;
useGui = false;
}
}
function OnGUI(){
if(isInside){
if(useGui){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 300, 30), "Press E to call your cousin");
}
}
}
You already have a lot of booleans at your disposal, you shouldn’t create more, just for the purpose to disable the gui forever, you could just use what you have, like for example the hasMadePhoneCall
function OnGUI(){
if(isInside){
if(useGui && !hasMadePhoneCall){
GUI.Label(new Rect(Screen.width/2 - 75, Screen.height - 100, 300, 30), "Press E to call your cousin");
}
}
}
That way, when you make the phone call, the gui won’t appear.
#pragma strict
var showGUI : boolean = true;
function Update()
{
if(Input.GetKeyDown(KeyCode.E))
showGUI = false;
//Not sure if you want to actually destroy the script if you have other code in it that you need to use,
//But if you DO want to destroy it, just destroy it when showGUI is false. I'd suggest putting any other code
//in another script if you're destroying this.
if(!showGUI)
Destroy (this);
}
function OnGUI()
{
if(showGUI)
{
if(GUI.Button(new Rect(0, 0, 128, 128), "Hide GUI"))
{
showGUI = false;
}
}
}
//c-sharp example
using UnityEngine;
using System.Collections;
public class Example : MonoBehaviour
{
bool showGUI = true;
void Update()
{
if(Input.GetKeyDown(KeyCode.E))
showGUI = false;
//Not sure if you want to actually destroy the script if you have other code in it that you need to use,
//But if you DO want to destroy it, just destroy it when showGUI is false. I'd suggest putting any other code
//in another script if you're destroying this.
if(!showGUI)
Destroy (this);
}
void OnGUI()
{
if(showGUI)
{
if(GUI.Button(new Rect(0, 0, 128, 128), "Hide GUI"))
{
showGUI = false;
}
}
}
}