Search Unity

problem with OnMouseDown !

Discussion in 'Scripting' started by MR.Dawoodi, Dec 14, 2010.

  1. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    hi there !
    i write an script , this script drag in object.
    if click on object must show a GUI window.
    but this have a error :confused:
    where is prob ?

    tnx
    sry 4 my lang :D
     
  2. pakfront

    pakfront

    Joined:
    Oct 6, 2010
    Posts:
    551
    OnGUI should not go inside OnMouseDown().

    Code (csharp):
    1. var clicked = false;
    2. function OnMouseDown() {
    3.  clicked = true;
    4. }
    5.  
    6. function OnGUI() {
    7.  if (clicked) windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
    8. }
     
  3. MR.Dawoodi

    MR.Dawoodi

    Joined:
    Dec 11, 2010
    Posts:
    22
    thank's pakfront ,
    but it not work !
    this have error , "Unknow identifier : WindowFunction" :(
    what's prob ?
     
  4. Ostagar

    Ostagar

    Joined:
    Sep 29, 2010
    Posts:
    445
    Mr.Dawoodi, pakfront was simply illustrating where OnGUI() should go since it was in the wrong place in your original code. Apply that lesson to your original code, don't replace all your code with his.

    I.e., you still must define windowRect and WindowFunction. :)

    Tip #1: Watch your indentation when you add curly braces. After every { it's a good practice to add a level of indentation e.g. with a <tab> or a few spaces, and after every } to remove a level of indentation. This makes your code easier to read/understand and makes you less likely to forget of misplace an { or an }.

    Tip #2: When you post code, enclose them in CODE rather than QUOTE. You may have to click "Go Advanced" to see that option. It'll look like a # sound. This makes your code easier to read on the forums.

    Example without these tips:

    Example with these tips:
    Code (csharp):
    1.  
    2. if (song.title == "paint it black") {
    3.    if (door.color == "red") {
    4.       door.paint("black");
    5.    }
    6. }
     
    Last edited: Dec 16, 2010
  5. poncho

    poncho

    Joined:
    Dec 10, 2010
    Posts:
    65
    if you are using the code like that

    function OnMouseDown()
    {
    function OnGUI() {
    windowRect = GUI.Window (0, windowRect, WindowFunction, "My Window");
    }

    function WindowFunction (windowID : int) {

    }
    the WindowFunction would need a parameter, cuz if it doesnt have it, it means that is a var not a function
    Unknown identifier means that WindowFunction was not instantiated as a var
    or not called by the right way as a function

    well this issue was a week ago hope it helps anyway