Dialogue is lag in exe.

When main character(A) close to the npc(B), press the space key will dialogue with B.

Play in Unity3.3 is work goes will.

But when I run in exe, press the space key isn’t response, need press many times will have response.

As below is my code:

var dialog1 : boolean = false ; 
var npc:GUISkin;
 
function Update() { }
 
function OnTriggerStay (myPlayer :Collider) {
if(Input.GetKeyUp("space")){
dialog1=true ;
}
}
function OnTriggerExit (myPlayer : Collider) {
dialog1=false;
}
 
function OnGUI(){
GUI.skin = npc;
if(dialog1 == true){
GUI.Box(Rect(5,Screen.height-Screen.height/4, Screen.width-10,Screen.height/4),"npc : 「・・・・・・」");
}
}

What’s my problem?

Thanks a lot!

maybe try saying that dialog1 is true 2 times on GetKeyDown, and Up. First try it with GetKeyDown only, if it still lags then try both.

like so:

function OnTriggerStay (myPlayer :Collider) {
    if(Input.GetKeyDown("space")){
        dialog1=true ;
     }
    if(Input.GetKeyUp("space")){
        dialog1=true ;
     }
}

and I would really try to use something better than Unity’s GUI. There’s a free and awesome GUI here http://forum.unity3d.com/threads/87917-Prime31-UIToolkit-Multi-Resolution-GUI-Solution-Ready-for-Use...and-it-s-free

the Unity 3D GUI could be what’s causing the lag. Unity’s OnGUI is just more resource expensive than it should be.