Search Unity

Javascript GUI error

Discussion in 'Immediate Mode GUI (IMGUI)' started by Spacemarine658, Aug 19, 2014.

Thread Status:
Not open for further replies.
  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 I know its probably because the player is teleported rather than moving out of the OnTriggerExit how do i fix this im new to programming as a whole let alone GUI

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

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Duplicate topics are not allowed.

    --Eric
     
Thread Status:
Not open for further replies.