Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Javascript GUI error

Discussion in 'Scripting' started by Spacemarine658, Aug 18, 2014.

  1. Spacemarine658

    Spacemarine658

    Joined:
    Dec 9, 2012
    Posts:
    14
    if the GUI is up when the player dies it stays up after respawn even though the player is out of the OnTriggerEnter for the GUI

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. var theDoor : Transform;
    4. private var doorIsClosed = true;
    5. private var drawGUI = false;
    6.  
    7. function Update ()
    8. {
    9.     if (drawGUI == true && Input.GetKeyDown(KeyCode.F))
    10.     {
    11.         changeDoorState();
    12.     }
    13. }
    14.  
    15.  
    16. function OnTriggerEnter (theCollider : Collider)
    17. {
    18.     if (theCollider.tag == "Player")
    19.     {
    20.         drawGUI = true;
    21.     }
    22. }
    23.  
    24. function OnTriggerExit (theCollider : Collider)
    25. {
    26.     if (theCollider.tag == "Player")
    27.     {
    28.         drawGUI = false;
    29.     }
    30. }
    31.  
    32. function OnGUI ()
    33. {
    34.     if (drawGUI == true)
    35.     {
    36.         GUI.Box (Rect (Screen.width*0.5-51, 400, 102, 22),"Press F to open");
    37.     }
    38.  
    39. }
    40.  
    41. function changeDoorState ()
    42. {
    43.     if (doorIsClosed == true)
    44.     {
    45.         theDoor.animation.CrossFade("Door Open");
    46.         //theDoor.audio.PlayOneShot();
    47.         doorIsClosed = false;
    48.         yield WaitForSeconds(3);
    49.         theDoor.animation.CrossFade("Door Close");
    50.         //theDoor.audio.PlayOneShot();
    51.         doorIsClosed = true;
    52.     }
    53. }
    54.  
     
  2. mathias234

    mathias234

    Joined:
    Sep 9, 2012
    Posts:
    239
    I think OnTriggerExit only is called when the physical object moves through the colllider so maybe if its teleported it doesnt get called
     
  3. Spacemarine658

    Spacemarine658

    Joined:
    Dec 9, 2012
    Posts:
    14
    how could I fix that?
     
  4. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
    Set drawGUI to false when you respawn the player...
     
  5. Spacemarine658

    Spacemarine658

    Joined:
    Dec 9, 2012
    Posts:
    14
    how can I set that I'm new to scripting lol