Search Unity

Problem with Next Level Code

Discussion in 'Scripting' started by Knight12ify, Aug 24, 2011.

  1. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    Code (csharp):
    1.  
    2. var loadLevel = 0 ;
    3. var Caption = "the celler"
    4.  
    5. function OnMouseDown() {
    6.  
    7.      //Load the requested level
    8.  
    9.      Application.LoadLevel(loadLevel) ;
    10.  
    11. }
    12.  
    13. function OnGUI () {
    14.  
    15.  
    16.     GUI.Button (Rect (200,200,100,20), GUIContent ("Click me",
    17.  
    18.         "Do you want to enter" + Caption + "?"));
    19.  
    20.     GUI.Label (Rect (200,230,100,100), GUI.tooltip);
    21.  
    22. }
    23.  
    Okay, so this is what I want the code to do: If I have this code selected over an object, when the mouse waves over the object or the player looks at the object, I want a caption to show that says click me, when the mouse hovers over the caption it shows: do you want to enter the celler. And when you click that, it takes you to the next area, but only if your looking at the object.

    This is what it does: At the top of the screen, there is a small caption that says click me, the mouse hovers over it and it says: do you want to enter the celler. Its just there, I'm not even looking at the celler door and it says: click me, I hover over it, do you want to enter the celler. If I click it, nothing happens, I just click it. When I move in front of the celler door, look at the celler and do it, I need to click on the celler to enter the celler.

    Can somebody here please fix this problem?
     
  2. appels

    appels

    Joined:
    Jun 25, 2010
    Posts:
    2,687
    what do you want to know ?
     
  3. oneXwork

    oneXwork

    Joined:
    Mar 3, 2011
    Posts:
    266
    maybe this is what you want:

    create a 3d text named "Click me!" on near a 3d Object
    add a colliderbox to it
    add a script to the Click me
    Use onMouseEnter() function and display a text " do you want to enter the celler"
    Code (csharp):
    1.  
    2. var IsDisplayMessage:boolean = false;
    3. function OnMouseEnter() {
    4.       IsDisplayMessage = true;
    5. }
    6.  
    7. function OnGUI() {
    8.     if(IsDisplayMessage)
    9.     GUI.Label (Rect (200,230,100,100),"Do you want to enter" + Caption + "?");
    10.  
    11. }
    12. function OnMouseExit() {
    13.       IsDisplayMessage = false;
    14. }
    15. function OnMouseDown() {
    16.  
    17.      //Load the requested level
    18.  
    19.      Application.LoadLevel(loadLevel) ;
    20.  
    21. }
    22.  
     
  4. Knight12ify

    Knight12ify

    Joined:
    May 21, 2010
    Posts:
    520
    Please elaborate, what do I do?

    What script do I add to the Click Me? Is it this one?

    I do not understand this part at all.
     
  5. oneXwork

    oneXwork

    Joined:
    Mar 3, 2011
    Posts:
    266
    Yes,the one that is coded...