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. Dismiss Notice

display GUI on trigger2d enter then press button to enter

Discussion in 'Scripting' started by Nvikelo, Feb 25, 2015.

  1. Nvikelo

    Nvikelo

    Joined:
    May 28, 2014
    Posts:
    11
    I am a newb at coding and i dont know how to add a press the button to c***inue to next level type thing.
    HELP

    Code (JavaScript):
    1. #pragma strict
    2. import UnityEngine.UI;
    3. var textToUse = "Text";
    4. var text : Text;
    5. var levelload : boolean;
    6. function Start ()
    7. {
    8.     text.text = "";
    9. }
    10. function OnTriggerEnter2D(other: Collider2D) {
    11.    
    12.         text.text = "" + textToUse;
    13.         levelload = true;
    14.        
    15.                 if(Input.GetKeyDown"e"){
    16. Application.LoadLevel("garage"); // it number or name, string
    17.     }
    18. }
    19.  
    20. function OnTriggerExit2D(other: Collider2D) {  
    21.  
    22.          
    23.             text.text = "";
    24.             levelload = false;
    25. }
     
  2. mgear

    mgear

    Joined:
    Aug 3, 2010
    Posts:
    8,937
    Hi,

    Check couple tutorials first, then you'll get quick progress:
    http://unity3d.com/learn/tutorials/modules

    You need to put Input inside Update loop, TriggerEnter gets called just once you enter it, it doesnt "loop"..
     
  3. Nvikelo

    Nvikelo

    Joined:
    May 28, 2014
    Posts:
    11
    so in an update function
     
  4. Nvikelo

    Nvikelo

    Joined:
    May 28, 2014
    Posts:
    11
    so in an update function