Search Unity

OnMouseOver? (this is a special case)

Discussion in 'Scripting' started by iceshaft07, May 2, 2011.

  1. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Alright, so I have an FPS game on the iPhone I am working on. I have a GUIButton for bringing up a menu in the game, as well as chatting to other users over network play.

    Tapping the screen causes the player to shoot.

    My problem is this-- when tapping the menu / chat button, the player shoots. This is specifically because I use Input.GetMopuseButtonDown(0) to determine if the player is tapping the screen.

    I attempted to use the OnMouseOver suggestion Unity provides in the docs by using GUIContent("Menu","onMouseOver") and GUI.tooltip, but this does not work because the 'mouse' is never over a GUIButton until it is pressed.

    I looked into using touchphases instead but I don't think that will work since all I have access to is touchPhase.began, which won't help me if I use that as well to shoot.

    Anyone have any ideas?

    Side note:
    I'll be working on it right now and have some ideas, but usually posting it gives me a second to actually /think/ about it.
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    OnGUI is not suited for iPhone especially with tooltips, you will need to use something else that reacts to touches correctly as touch has no "over" its technically always in drag mode (as touch = LMB)
     
  3. AcidArrow

    AcidArrow

    Joined:
    May 20, 2010
    Posts:
    11,750
    How would on mouse over work on ios? You can't have your finger over something without touching the surface, and touching equals clicking.

    Also, yeah, OnGUI is evil, EVIL I TELL YOU (on ios at least) :p
     
  4. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    Dreamora, do you have any suggestions? I am not looking to use the tool tips, I am just trying to get the code to work such that Input.GetMouseButtonDown(0) doesn't also shoot when the GUI.Button is pressed.

    AcidArrow, I was hoping maybe there was something that existed such as GUI.IsButtonHeldDown(), but there isn't. And while I agree that OnGUI isn't my most favorite thing, it does provide a simple and effective way of setting up menus. I have been able to do just about everything else I have wanted to with it, this is just a special case scenerio (though, I wish Unity would/could do something about the aweful number of drawcalls the GUI takes up).

    I've tried things like checking mouse button down in the GUI, and setting an ignore flag, but that doesn't work quite the way I want it (I have reactionary code, rather than preventative code). Especially, since checking if the mouse is in the button requires the mouse be down defeats the code.

    But this is especially difficult with TextFields since I don't even have a tooltip to work off of-- I feel like I am back at square one after all I've done.
     
  5. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    I have absolutely no experience with iOS dev, but I imagine you probably want to use a GUITexture as your button and forgo using OnGUI altogether... then use Input.touches to check if the touch position is contained inside the GUITexture Rect, otherwise shoot.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    I would go with EZGUI, but that might be cause I used already its root, Sprite Manager 1 and now SM2 and EZGUI
     
  7. iceshaft07

    iceshaft07

    Joined:
    Jul 23, 2010
    Posts:
    293
    :-/ I'm talented, but I'm quite poor. I was hoping for a free solution.

    I have it mostly working.

    One idea I had, (and I'm not sure about this) is to devide GetMouseButtonDown(0), and GetMouseButton(0) into three phases--

    The first is GetMouseButtonDown(0).
    The next is the first run through GetMouseButton(0)
    The third is all subsequent runs through GetMouseButton(0).