Search Unity

simple question

Discussion in 'Scripting' started by sr, Sep 18, 2005.

  1. sr

    sr

    Joined:
    Sep 18, 2005
    Posts:
    70
    hi there.

    i'm really bad at scripting.
    wrote this to give a restart per button to a racing game:


    function Update () {

    if (Input.GetButton ("Jump")) {
    Application.LoadLevel (0);

    }
    }


    the problem is, it will only restart ONCE.
    i guess it has to do with the "function Update ()", but i haven't found about this issue in forums or manual.
    this is probably really embarassing, but i would be glad if someone could give me a hint.

    thanks!
     
  2. DaveyJJ

    DaveyJJ

    Joined:
    Mar 24, 2005
    Posts:
    1,558
    This is what I put into a text object to make it a button ...

    Code (csharp):
    1.  
    2. function OnMouseDown () {
    3.     /* load a specific scene by name */
    4.     Application.LoadLevel ("namegoeshere");
    5. }
    6.  
    And if you create a script with the following in it, and attach it to the text object, it'll change it's appearance on mouse over ...

    Code (csharp):
    1.  
    2. /* This behavior script changes the material color to the
    3. highlightColor when the mouse hovers over the text.
    4. The highlightColor can be modified in the inspector. */
    5.  
    6. /* It also scales the object to be slightly larger on mouse enter,
    7. then back to normal size when the mouse leaves the object. */
    8.  
    9. var highlightColor = Color.yellow;
    10.    
    11. function OnMouseEnter () {
    12.     guiText.material.color = highlightColor;
    13.     transform.localScale = Vector3 (1.2, 1.2, 1.2);
    14. }
    15.  
    16. function OnMouseExit () {
    17.     guiText.material.color = Color.white;
    18.     transform.localScale = Vector3 (1, 1, 1);
    19. }
    20.  
     
  3. sr

    sr

    Joined:
    Sep 18, 2005
    Posts:
    70
    thanks, david,

    but i think i formulated the question wrong, sorry!
    the level is reloaded if the player presses e.g. space ("jump") now (no need for a on-screen button),
    but it will only do this once.

    if you manage to crash the car A 2ND TIME, you'll not be able to reload the scene anymore.
     
  4. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    Is this script attached to a game object in the racing level scene?

    Does the game object you attached the script to disappear when loading the level?