Search Unity

4.6 UI and raycasting.

Discussion in 'UGUI & TextMesh Pro' started by Alessio89, Aug 22, 2014.

  1. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    First of all: good job on the new UI. It's actually pretty good!
    I'm in the process of porting all of my UIs from NGUI to the new UI System and so far so good.
    I now have a question, though: my player uses a "click-to-move" system and I need to check that when you click you're not in fact overing a menu element. At first I tought to use raycasting (seems the most obvious to me) from the mouse and if it intersects any UI before the terrain, it should not move.
    The problem is, how do I check with a raycast if I'm using a ScreenSpace - Overlay canvas (that is, I don't have a Camera that renders the UI)?

    Should I ditch the raycasting and instead use a global boolean value and set it in OnPointerEnter and OnPointerExit? Or am I doing it completely wrong and missing something obvious?
     
  2. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    import UnityEngine.EventSystems;
    then use
    EventSystemManager.currentSystem.IsPointerOverEventSystemObject()
     
    Alessio89 likes this.
  3. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    That's it, I was missing something obvious as stated :) Thanks!
     
  4. StarManta

    StarManta

    Joined:
    Oct 23, 2006
    Posts:
    8,775
    I don't know if I would call it 'obvious'; I had to find it on the forums as well.
     
  5. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    Well, yeah I mispoke. I meant "quick and easy" rather than "obvious" :D
     
    StarManta likes this.
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    If you are using point and click for your game you might also want to use the event system for your 3d movement also :) It is fully supported!
     
  7. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    :eek: I didn't know about that. I'll make sure to check that out. I haven't looked in depth into the event system. Is it documented somewhere or do we have to discover it ourselves, for now? I can't seem to find anything on the API page...
     
  8. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,225
    We have some docs, but more will be coming over the next few weeks.
     
    Alessio89 likes this.
  9. Alessio89

    Alessio89

    Joined:
    Aug 8, 2014
    Posts:
    20
    Awesome! Can't wait! Meanwhile I'll just get my hands dirty and do a lot of testing :D

    P.s.: You really did a great job with the new ui system, I'm sure the finished version will be even more awesome :)