Search Unity

openurl, is automatically opening

Discussion in 'Scripting' started by phil.cooper@mtcl.net, Apr 6, 2010.

  1. phil.cooper@mtcl.net

    phil.cooper@mtcl.net

    Joined:
    Nov 10, 2009
    Posts:
    265
    i am using this script to link to pdf's from buttons. but when i run the game, the pdf opens automatically without having to click the button. any ideas what im doing wrong?

    Code (csharp):
    1. var selectionGridInt : int = 0;
    2. var selectionStrings : String[] = ["Grid 1", "Grid 2", "Grid 3", "Grid 4"];
    3.  
    4. function OnGUI () {
    5.  
    6. GUI.Box(Rect(Screen.width / 7, 0, Screen.width - (Screen.width / 7), Screen.height / 5), "");
    7. selectionGridInt = GUI.SelectionGrid (Rect (Screen.width / 7, Screen.height / 64, 300, Screen.height / 6), selectionGridInt, selectionStrings, 2);
    8.  
    9. if(selectionGridInt == 0)
    10. Application.OpenURL("file://C:\\Users\\phil.cooper\\Documents\\MY TEMP FOLDER\\R&D\\UNITY 3D\\texture baking test\\DATA\\CERTIFICATE_DEEP_CLEAN.pdf");
    11.  
    12. if(selectionGridInt == 1)
    13. print( "test" );
    14.  
    15.  
    16. if(selectionGridInt == 2)
    17. print( "test1" );
    18.  
    19.  
    20. if(selectionGridInt == 3)
    21. print( "test2" );
    22. }
     
  2. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    not sure but is it because you are setting selectGridInt to 0 at the top... so when your OnGUI is run, the first if statement is already true.
     
  3. phil.cooper@mtcl.net

    phil.cooper@mtcl.net

    Joined:
    Nov 10, 2009
    Posts:
    265
    what should i set selectGridInt to?
     
  4. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    I'm not sure how SelectionGrid work as not used them before... but just try initialising it at the top to anything other than 0 - 3, to see if that narrows your problem down.
     
  5. phil.cooper@mtcl.net

    phil.cooper@mtcl.net

    Joined:
    Nov 10, 2009
    Posts:
    265
    that almost worked. now it doesnt load up by itself when i play the game, only when i press the button.

    but it keeps loading it up again as soon as i close it without pressing the button.
     
  6. fallingbrickwork

    fallingbrickwork

    Joined:
    Mar 16, 2009
    Posts:
    1,072
    You'll have to look at your logic. You are setting the Int to 0 to open the pdf, so once it is set (as it's global), it will remain set. Can you not create the SelectionGridInt in the GUI function? or initialise it in first line of the GUI.