Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

pop up box

Discussion in 'Getting Started' started by joytdecastro, Feb 28, 2015.

  1. joytdecastro

    joytdecastro

    Joined:
    Feb 15, 2015
    Posts:
    21
    please help me on this?? i want to view a pop up box when the player accomplish the each missions, and disable it after 5 sec. but the gui box is not viewing. here's my code..

    Code (JavaScript):
    1. #pragma strict
    2.  
    3. static var currentScore : int = 0;
    4. var target : GameObject;
    5. var isObjective1Complete : boolean = false;
    6. var isObjective2Complete : boolean = false;
    7. var isObjective3Complete : boolean = false;
    8. var offsetY : float = 40;
    9. var sizeX : float = 100;
    10. var sizeY : float = 40;
    11. var skin : GUISkin;
    12. var timer = 0.0;
    13.  
    14. function Start () {
    15.     PlayerPrefs.SetFloat("Coins: ", currentScore);
    16.     target = GameObject.FindGameObjectWithTag("Player");
    17.     currentScore = PlayerPrefs.GetFloat("Coins: ");
    18. }
    19.  
    20.  
    21. function Update () {
    22. timer += Time.deltaTime;
    23.   if (currentScore == 100) {
    24.     isObjective1Complete = true;
    25.    
    26.   }
    27.  
    28.   if (car.attractCoins == true && Vector3.Distance(transform.position,target.transform.position) == 2) {
    29.     isObjective2Complete = true;
    30.   }
    31.  
    32.   if (GameControlScriptjs.score >= 500) {
    33.     isObjective3Complete = true;
    34.   }
    35.  
    36.   if (isObjective1Complete && isObjective2Complete && isObjective3Complete == true) {
    37.     Application.LoadLevel ("mission complete1");
    38.   }
    39. }
    40.  
    41.  
    42. function OnGUI () {
    43.     GUI.skin=skin;
    44.     timer += Time.deltaTime;
    45.    
    46.     GUI.Box (new Rect (Screen.width/2-sizeX/2, offsetY, sizeX, sizeY), "Coins: " + currentScore);
    47.    
    48.     if (isObjective3Complete)
    49.     {
    50.          GUI.Box(Rect(20, 20, 220, 25), "You already reach 500 score!");
    51.         if (timer >= 5.0)
    52.         {
    53.             isObjective3Complete = false;
    54.         }
    55.     }
    56.     if (isObjective1Complete)
    57.     {
    58.          GUI.Box(Rect(20, 20, 220, 25), "You already reach 100 coins!");
    59.         if (timer >= 5.0)
    60.         {
    61.             isObjective1Complete = false;
    62.         }
    63.        
    64.     }
    65.     if (isObjective2Complete)
    66.     {
    67.          GUI.Box(Rect(20, 20, 220, 25), "You already get 2 power ups!");
    68.         if (timer >= 5.0)
    69.         {
    70.             isObjective2Complete = false;
    71.         }
    72.     }
    73.    
    74. }
    75.  
    76.