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.

Help with Vuforia project

Discussion in 'Editor & General Support' started by Spinnernicholas, Dec 4, 2013.

  1. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    its alright. thanks again for the help
     
  2. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    MonoBehaviour should be right. That's weird.
     
  3. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    it is right. but Im pretty sure you have to type the using unity and using system for it to work

    because i get the error

    Assets/MouseHandler.cs(1,28): error CS0246: The type or namespace name `MonoBehaviour' could not be found. Are you missing a using directive or an assembly reference?
     
  4. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Lol,

    add at the top:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
     
  5. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
  6. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    Yea I tried that now I have a lot of errors

    Code (csharp):
    1.  
    2.  
    3. Assets/MouseHandler.cs(25,34): error CS0200: Property or indexer `UnityEngine.Touch.phase' cannot be assigned to (it is read only)
    4.  
    5. Assets/MouseHandler.cs(29,94): error CS1061: Type `UnityEngine.Vector2' does not contain a definition for `X' and no extension method `X' of type `UnityEngine.Vector2' could be found (are you missing a using directive or an assembly reference?)
    6.  
    7. Assets/MouseHandler.cs(29,112): error CS1061: Type `UnityEngine.Vector2' does not contain a definition for `Y' and no extension method `Y' of type `UnityEngine.Vector2' could be found (are you missing a using directive or an assembly reference?)
    8.  
    9. Assets/MouseHandler.cs(29,114): error CS1502: The best overloaded method match for `UnityEngine.Vector3.Vector3(float, float)' has some invalid arguments
    10.  
    11. Assets/MouseHandler.cs(29,114): error CS1503: Argument `#1' cannot convert `object' expression to type `float'Assets/MouseHandler.cs(29,50): error CS1502: The best overloaded method match for `UnityEngine.Camera.ScreenPointToRay(UnityEngine.Vector3)' has some invalid arguments
    12.  
    13.  
    14. Assets/MouseHandler.cs(29,50): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Vector3'
    15.  
    16. Assets/MouseHandler.cs(59,39): error CS0246: The type or namespace name `rect' could not be found. Are you missing a using directive or an assembly reference?
    17.  
    18. Assets/MouseHandler.cs(59,29): error CS1502: The best overloaded method match for `UnityEngine.GUI.Label(UnityEngine.Rect, string)' has some invalid arguments
    19.  
    20. Assets/MouseHandler.cs(59,29): error CS1503: Argument `#1' cannot convert `object' expression to type `UnityEngine.Rect'
    21.  
    22.  
     
  7. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    That's because I copied it from before we fixed it.

     
  8. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Capitalize rect to Rect.
     
  9. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    i fixed all but

    Assets/MouseHandler.cs(25,34): error CS0200: Property or indexer `UnityEngine.Touch.phase' cannot be assigned to (it is read only)
     
  10. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    that should be fixed by changing the "=" to "==".
     
  11. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    i fixed everything
     
  12. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MouseHandler: MonoBehaviour
    6. {
    7.     public bool enableDebug;
    8.     private string debugOutput = "";
    9.  
    10.     void Update()
    11.     {
    12.         if(Input.touchCount > 0)
    13.         {
    14.             Touch touch = Input.touches[0];
    15.             if(touch.phase == TouchPhase.Began)
    16.             {
    17.                 Ray ray = camera.ScreenPointToRay(new Vector3(touch.position.X, touch.position.Y));
    18.                 RaycastHit hit;
    19.                 if(Physics.Raycast(ray, out hit, 100))
    20.                 {
    21.                     debugOutput += "Touched Collider: " + hit.collider.name + "\n";
    22.                     hit.collider.SendMessage("OnTouch");
    23.                 }
    24.             }
    25.         }
    26.     }
    27.    
    28.     void OnGUI()
    29.     {
    30.         if(enableDebug)
    31.         {
    32.             GUI.Label(new Rect(0f,0f,Screen.width,Screen.height), debugOutput)
    33.         }
    34.     }
    35. }
    36.  
     
  13. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, cool. Now enable debug in the inspector and start it up. Tell me how it looks. Hopefully, the gui label won't dominate the screen. Then try and click the button and tell me if any text appears.
     
  14. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    how do you check the debug?
     
  15. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    The debug should display on top of everything else. If there is no debug text, then you might not see anything. But, you have to make sure that Enable Debug is on in my camera script by setting it to True in the inspector.
     
  16. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    its checked but nothing showed up
     
  17. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    ok, let's try this, change:

    Code (csharp):
    1. private string debugOutput = "";
    to:


    Code (csharp):
    1. private string debugOutput = "Debug Started.\n";
     
  18. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Then it should say "Debug Started." when you start it up.
     
  19. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    it shows debug started but nothing else

    should the button be parented to the imagetarget ( it is)

    and should your button handler script be on the button (it is) or on the image target?
     
  20. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Image Target should be the parent of button and my button handler script should be on the button. You had it setup right in the screen shots.
     
  21. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    just making sure since nothing is working
     
  22. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Here, I changed it so it should print debug info whenever you tap on the screen.

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MouseHandler: MonoBehaviour
    6. {
    7.     public bool enableDebug;
    8.     private string debugOutput = "Debug Started.\n";
    9.    
    10.     void Update()
    11.     {
    12.         if(Input.touchCount > 0)
    13.         {
    14.             Touch touch = Input.touches[0];
    15.             if(touch.phase == TouchPhase.Began)
    16.             {
    17.                 debugOutput += "New Touch Detected.\n"
    18.                 Ray ray = camera.ScreenPointToRay(new Vector3(touch.position.X, touch.position.Y));
    19.                 RaycastHit hit;
    20.                 if(Physics.Raycast(ray, out hit, 100))
    21.                 {
    22.                     debugOutput += "Touched Collider: " + hit.collider.name + "\n";
    23.                     hit.collider.SendMessage("OnTouch");
    24.                 }
    25.             }
    26.         }
    27.     }
    28.    
    29.     void OnGUI()
    30.     {
    31.         if(enableDebug)
    32.         {
    33.             GUI.Label(new Rect(0f,0f,Screen.width,Screen.height), debugOutput)
    34.         }
    35.     }
    36. }
    37.  
     
  23. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    it detects touch but still no animation
     
  24. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    I think I know the problem, try this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class MouseHandler: MonoBehaviour
    6. {
    7.     public bool enableDebug;
    8.     private string debugOutput = "Debug Started.\n";
    9.    
    10.     void Update()
    11.     {
    12.         if(Input.touchCount > 0)
    13.         {
    14.             Touch touch = Input.touches[0];
    15.             if(touch.phase == TouchPhase.Began)
    16.             {
    17.                 debugOutput += "New Touch Detected.\n"
    18.                 Ray ray = camera.ScreenPointToRay(new Vector3(touch.position.X, touch.position.Y));
    19.                 RaycastHit hit;
    20.                 if(Physics.Raycast(ray, out hit))
    21.                 {
    22.                     debugOutput += "Touched Collider: " + hit.collider.name + "\n";
    23.                     hit.collider.SendMessage("OnTouch");
    24.                 }
    25.             }
    26.         }
    27.     }
    28.    
    29.     void OnGUI()
    30.     {
    31.         if(enableDebug)
    32.         {
    33.             GUI.Label(new Rect(0f,0f,Screen.width,Screen.height), debugOutput)
    34.         }
    35.     }
    36. }
    37.  
     
  25. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    Your amazing man!

    what did you do?

    and what lines would be safe to change to comment so it doesn't show up?
     
  26. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    and i need help with one more thing.

    how can I make this

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4. using System;
    5.  
    6. public class CameraDeviceMenu : MonoBehaviour
    7. {
    8.     #region NESTED
    9.    
    10.     // Defines which menu to show.
    11.     private enum MenuMode
    12.     {
    13.         MENU_OFF,            // Do not show a menu (default).
    14.         MENU_CAMERA_OPTIONS, // Show camera device options.
    15.         MENU_FOCUS_MODES     // Show focus mode menu.
    16.     }
    17.    
    18.     #endregion // NESTED
    19.    
    20.    
    21.    
    22.     #region PRIVATE_MEMBER_VARIABLES
    23.    
    24.     // Currently active menu.
    25.     private MenuMode mMenuToShow = MenuMode.MENU_OFF;
    26.    
    27.     // Check if a menu button has been pressed.
    28.     private bool mButtonPressed = false;
    29.    
    30.     // Check if flash is currently enabled.
    31.     private bool mFlashEnabled = false;
    32.    
    33.     // Contains the currently set auto focus mode.
    34.     private CameraDevice.FocusMode mFocusMode =
    35.         CameraDevice.FocusMode.FOCUS_MODE_NORMAL;
    36.    
    37.     // Contains the rectangle for the camera options menu.
    38.     private Rect mAreaRect;
    39.    
    40.     #endregion // PRIVATE_MEMBER_VARIABLES
    41.    
    42.    
    43.    
    44.     #region UNTIY_MONOBEHAVIOUR_METHODS
    45.    
    46.     public void Start()
    47.     {
    48.         // Setup position and size of the camera menu.
    49.         computePosition();
    50.     }
    51.    
    52.    
    53.     public void OnApplicationPause(bool pause)
    54.     {
    55.         // Upon resuming reactivate the torch if it was active before pausing:
    56.         if (!pause)
    57.         {
    58.             if (mFlashEnabled)
    59.             {
    60.                 mFlashEnabled = CameraDevice.Instance.SetFlashTorchMode(true);
    61.             }
    62.         }
    63.     }
    64.    
    65.    
    66.     public void Update()
    67.     {
    68.         // If the touch event results from a button press it is ignored.
    69.         if (!mButtonPressed)
    70.         {
    71.             // If finger is removed from screen.
    72.             if (Input.GetMouseButtonUp(0))
    73.             {
    74.                 // If menu is not rendered.
    75.                 if (mMenuToShow == MenuMode.MENU_OFF)
    76.                 {
    77.                     // Show menu.
    78.                     mMenuToShow = MenuMode.MENU_CAMERA_OPTIONS;
    79.                 }
    80.                 // If menu is already open.
    81.                 else
    82.                 {
    83.                     // Close menu
    84.                     mMenuToShow = MenuMode.MENU_OFF;
    85.                 }
    86.             }
    87.         }
    88.         else
    89.         {
    90.             mButtonPressed = false;
    91.         }
    92.     }
    93.    
    94.    
    95.     // Draw menus.
    96.     public void OnGUI()
    97.     {
    98.         switch (mMenuToShow)
    99.         {
    100.         case MenuMode.MENU_CAMERA_OPTIONS:
    101.             DrawMenu();
    102.             break;
    103.            
    104.         case MenuMode.MENU_FOCUS_MODES:
    105.             DrawFocusModes();
    106.             break;
    107.            
    108.         default:
    109.             break;
    110.         }
    111.     }
    112.    
    113.     #endregion // UNTIY_MONOBEHAVIOUR_METHODS
    114.    
    115.    
    116.    
    117.     #region PRIVATE_METHODS
    118.    
    119.     // Draw menu to control camera device.
    120.     private void DrawMenu()
    121.     {
    122.         computePosition();
    123.        
    124.         // Setup style for buttons.
    125.         GUIStyle buttonGroupStyle = new GUIStyle(GUI.skin.button);
    126.         buttonGroupStyle.stretchWidth = true;
    127.         buttonGroupStyle.stretchHeight = true;
    128.        
    129.         GUILayout.BeginArea(mAreaRect);
    130.        
    131.         GUILayout.BeginHorizontal(buttonGroupStyle);
    132.        
    133.         // Turn flash on or off.
    134.         if (GUILayout.Button("Toggle Flash", buttonGroupStyle))
    135.         {
    136.             if (!mFlashEnabled)
    137.             {
    138.                 // Turn on flash if it is currently disabled.
    139.                 CameraDevice.Instance.SetFlashTorchMode(true);
    140.                 mFlashEnabled = true;
    141.             }
    142.             else
    143.             {
    144.                 // Turn off flash if it is currently enabled.
    145.                 CameraDevice.Instance.SetFlashTorchMode(false);
    146.                 mFlashEnabled = false;
    147.             }
    148.            
    149.             mMenuToShow = MenuMode.MENU_OFF;
    150.             mButtonPressed = true;
    151.         }
    152.        
    153.         // Triggers auto focus:
    154.         if (GUILayout.Button("Autofocus", buttonGroupStyle))
    155.         {
    156.             if (CameraDevice.Instance.SetFocusMode(CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO))
    157.                 mFocusMode = CameraDevice.FocusMode.FOCUS_MODE_TRIGGERAUTO;
    158.            
    159.             mMenuToShow = MenuMode.MENU_OFF;
    160.             mButtonPressed = true;
    161.         }
    162.        
    163.         // Choose focus mode.
    164.         if (GUILayout.Button("Focus Modes", buttonGroupStyle))
    165.         {
    166.             mMenuToShow = MenuMode.MENU_FOCUS_MODES;
    167.             mButtonPressed = true;
    168.         }
    169.        
    170.         GUILayout.EndHorizontal();
    171.        
    172.         GUILayout.EndArea();
    173.     }
    174.    
    175.    
    176.     // Draw menu to let user choose a focus mode.
    177.     private void DrawFocusModes()
    178.     {
    179.         CameraDevice.FocusMode newMode;
    180.         newMode = EnumOptionList(mFocusMode);
    181.        
    182.         // We set the new value only if the mode has changed.
    183.         if (newMode != mFocusMode)
    184.         {
    185.             if (CameraDevice.Instance.SetFocusMode(newMode))
    186.                 mFocusMode = newMode;
    187.            
    188.             mMenuToShow = MenuMode.MENU_OFF;
    189.             mButtonPressed = true;
    190.         }
    191.     }
    192.    
    193.    
    194.     // Helper function to automatically create an option list of an enum object.
    195.     private static CameraDevice.FocusMode EnumOptionList(
    196.         CameraDevice.FocusMode setMode)
    197.     {
    198.         Type modeType = setMode.GetType();
    199.        
    200.         // Get possible enum values.
    201.         CameraDevice.FocusMode[] modes =
    202.             (CameraDevice.FocusMode[])Enum.GetValues(modeType);
    203.        
    204.         // Setup style for list.
    205.         GUIStyle optionListStyle = new GUIStyle(GUI.skin.button);
    206.         optionListStyle.stretchHeight = true;
    207.         optionListStyle.stretchWidth = true;
    208.        
    209.         // Setup style for toggles.
    210.         // We use "button" style as template because default toggles are too
    211.         // small.
    212.         GUIStyle toggleStyle = new GUIStyle(GUI.skin.button);
    213.         toggleStyle.stretchHeight = true;
    214.         toggleStyle.stretchWidth = true;
    215.         toggleStyle.normal.textColor = Color.gray;
    216.         toggleStyle.onNormal.textColor = Color.gray;
    217.         toggleStyle.focused.textColor = Color.gray;
    218.         toggleStyle.onFocused.textColor = Color.gray;
    219.         toggleStyle.active.textColor = Color.gray;
    220.         toggleStyle.onActive.textColor = Color.gray;
    221.         toggleStyle.hover.textColor = Color.gray;
    222.         toggleStyle.onHover.textColor = Color.gray;
    223.        
    224.         // Setup style for active toggle.
    225.         // Setting active values for the toggle Style does not work so we create
    226.         // another style.
    227.         GUIStyle activeToggleStyle = new GUIStyle(toggleStyle);
    228.         activeToggleStyle.normal.textColor = Color.white;
    229.         activeToggleStyle.onNormal.textColor = Color.white;
    230.         activeToggleStyle.focused.textColor = Color.white;
    231.         activeToggleStyle.onFocused.textColor = Color.white;
    232.         activeToggleStyle.active.textColor = Color.white;
    233.         activeToggleStyle.onActive.textColor = Color.white;
    234.         activeToggleStyle.hover.textColor = Color.white;
    235.         activeToggleStyle.onHover.textColor = Color.white;
    236.        
    237.        
    238.         CameraDevice.FocusMode newMode = setMode;
    239.        
    240.         // We render the menu over the full screen.
    241.         GUILayout.BeginArea(new Rect(0, 0, Screen.width, Screen.height));
    242.        
    243.         GUILayout.BeginVertical();
    244.        
    245.         foreach (CameraDevice.FocusMode mode in modes)
    246.         {
    247.             if (mode == setMode)
    248.             {
    249.                 GUILayout.Toggle(true, mode.ToString(), activeToggleStyle);
    250.             }
    251.             else
    252.             {
    253.                 if (GUILayout.Toggle(false, mode.ToString(), toggleStyle))
    254.                 {
    255.                     newMode = mode;
    256.                 }
    257.             }
    258.         }
    259.        
    260.         GUILayout.EndVertical();
    261.        
    262.         GUILayout.EndArea();
    263.        
    264.         return newMode;
    265.     }
    266.    
    267.    
    268.     /// Compute the coordinates of the menu depending on the current orientation.
    269.     private void computePosition()
    270.     {
    271.         int areaWidth = Screen.width;
    272.         int areaHeight = (Screen.height / 5) * 2;
    273.         int areaLeft = 0;
    274.         int areaTop = Screen.height - areaHeight;
    275.         mAreaRect = new Rect(areaLeft, areaTop, areaWidth, areaHeight);
    276.     }
    277.    
    278.     #endregion // PRIVATE_METHODS
    279. }
    open with this button

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. [ExecuteInEditMode]
    6. public class GUI_settings : MonoBehaviour {
    7.     public Texture2D menu;
    8.    
    9.     // Use this for initialization
    10.     private void Start () {
    11.        
    12.     }
    13.    
    14.     // Update is called once per frame
    15.     private void Update () {
    16.        
    17.     }
    18.     private void OnGUI() {
    19.         if (GUI.Button (new Rect (Screen.width - (15*(Screen.width)/100),0,15*(Screen.width)/100,10*(Screen.height)/100), menu)) {
    20.             Application.LoadLevel(0);
    21.         }
    22.     }
    23. }
     
    Last edited: Dec 20, 2013
  27. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, I had the ray only cast 100 units, I changed it to cast infinitely.

    All you have to do to disable the debug, is to turn it off in the inspector on the camera script. (Enable Debug = False) I would delete the line

    Code (csharp):
    1.  
    2. debugOutput += "New Touch Detected.\n"
    3.  
    It is mostly redundant.
     
  28. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    That script looks like it is pretty independent. I don't see any straight forward way of opening it. If you put it on a GameObject, does it open up automatically.
     
  29. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    if you touch the screen
     
  30. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    It responds to you touching the screen? That's kinda of weird. So you want it to open only when they hit the gui button in the other script?
     
  31. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    yea. and if they are combined together thats fine . i just need it to open from a button being pressed because of the attack button
     
  32. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    In the first script:
    1. Comment out everything in Update().

    2. add this method:

    Code (csharp):
    1.  
    2. public void ShowMenu()
    3. {
    4.      mMenuToShow = MenuMode.MENU_CAMERA_OPTIONS;
    5. }
    6.  
     
  33. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    The second script:

    Code (csharp):
    1.  
    2. public class GUI_settings : MonoBehaviour {
    3.  
    4.     public Texture2D menu;
    5.     public CameraDeviceMenu cameraMenu;
    6.    
    7.     private void OnGUI() {
    8.         if (GUI.Button (new Rect (Screen.width - (15*(Screen.width)/100),0,15*(Screen.width)/100,10*(Screen.height)/100), menu)) {
    9.             cameraMenu.ShowMenu();
    10.         }
    11.     }
    12. }
    13.  
    And set Camera Menu to the object with the first script in the inspector.
     
  34. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    And don't forget the "Using" statements at the top.
     
  35. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    And the execute in edit mode attribute if you want it.
     
  36. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    ok it opens it. and now it needs to close which should be just an else right?
     
  37. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    hmm I can't figure out how to do that
     
  38. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    Ok i just found a problem with preview animation. after the monster attacks, it stops looping its idle animation
     
  39. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, so to have the button toggle the menu, you will need to use GUI.Toggle instead of GUI.Button.

    To do this, you will need to add a private bool variable to the second script, call it menuVisible and initialize it to False.

    replace the whole if statement with this:

    Code (csharp):
    1.  
    2. bool newVisible = Toggle(<your rect>, menuVisible, menu);
    3.  
    and

    Code (csharp):
    1.  
    2. if(newVisible != menuVisible)
    3. {
    4. if(menuVisible)
    5. {
    6.     cameraMenu.ShowMenu();
    7. }
    8. else
    9. {
    10.     cameraMenu.HideMenu();
    11. }
    12. }
    13.  
    Then create a second method in the menu script called HideMenu() and have it set mMenuToShow = MenuMode.MENU_OFF.
     
  40. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Forgot this in the menu toggle script. After the if statement add this.

    Code (csharp):
    1.  
    2. menuVisible = newVisible;
    3.  
     
  41. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    what do I put where <your rect> is?
     
  42. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Sorry for my vagueness on friday, I was trying to get a good answer out before leaving town for the weekend. Now, let me see....
     
  43. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Ok, so first, in the menu script make the update method look like this:

    Code (csharp):
    1.  
    2.     public void Update()
    3.     {
    4.         // If the touch event results from a button press it is ignored.
    5.         if (!mButtonPressed)
    6.         {
    7.             // If finger is removed from screen.
    8.             if (Input.GetMouseButtonUp(0))
    9.             {
    10.                 // If menu is not rendered.
    11.                 if (mMenuToShow == MenuMode.MENU_OFF)
    12.                 {
    13.                     // Show menu.
    14.                 //    mMenuToShow = MenuMode.MENU_CAMERA_OPTIONS;
    15.                 }
    16.                 // If menu is already open.
    17.                 else
    18.                 {
    19.                     // Close menu
    20.                     mMenuToShow = MenuMode.MENU_OFF;
    21.                 }
    22.             }
    23.         }
    24.         else
    25.         {
    26.             mButtonPressed = false;
    27.         }
    28.     }
    29.  
     
  44. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Then replace the other script with this:

    Code (csharp):
    1.  
    2. using UnityEngine;
    3. using System.Collections;
    4.  
    5. public class GUI_settings : MonoBehaviour
    6. {
    7.     public Texture2D menu;
    8.     public CameraDeviceMenu cameraMenu;
    9.    
    10.     private void OnGUI() {
    11.         if (GUI.Button (new Rect (Screen.width - (15*(Screen.width)/100),0,15*(Screen.width)/100,10*(Screen.height)/100), menu)) {
    12.             cameraMenu.ShowMenu();
    13.         }
    14.     }
    15. }
    16.  
     
  45. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    That will make it so clicking the button will open the menu. Then, clicking anywhere on the screen, not on the menu, will close it.
     
  46. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    hmm clicking the button doesn't open it now.
     
  47. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Is Camera Menu on the second script set to the Menu Script in the inspector?
     
  48. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    what is attached is "ARCamera (CameraDeviceMenu)"

    should this go after the show menu script or before?
    I just put it where the old update script was
     
  49. tredpro

    tredpro

    Joined:
    Nov 18, 2013
    Posts:
    511
    if i delete the update script it works how it was to where when you click the button it opens but you have to pick something to close it
     
  50. Spinnernicholas

    Spinnernicholas

    Joined:
    Jan 24, 2013
    Posts:
    125
    Can you post a screen shot of the inspector for me?