Search Unity

Trading Card Game - UI Interaction with 3D World

Discussion in 'UGUI & TextMesh Pro' started by Maurice94, Oct 17, 2019.

  1. Maurice94

    Maurice94

    Joined:
    Oct 9, 2019
    Posts:
    2
    Good evening!

    I got a problem. I am using the IBeginDragHandler / IDragHandler / IEndDragHandler interfaces for the dragging system of my UI card elements. This is working fine and I get all the responses, I'm looking for. My cards are parented to a PlayerHand game object in the hierarchy. When I start dragging, my Canvas becomes the new parent of the card I'm currently dragging and as soon as I call the OnEndDrag function, the card returns to its original parent.

    My main issue is, that I don't know how to make my UI elements interacting with the 3D game scene. I know, that the solution for this is probably Raycasting. However, I can not figure out, how to make this work. I tried to use LayerMasks, but ended up in a weird scenario, where I just had set the blockRaycasts property from the CanvasGroup to false in order to get a response from the Layermask underneath my card object. But this is not what I'm looking for, since I want to combine my game logic with the IDropHandler. And that's the problem - I know that the drag & drop system is UI only.

    I found another option in using the RectTransformUtility... did not work out in the end. I made some other experiments before... and it all worked out fine. But that was because my whole project was in 2D and I was able to use RectTransforms as DropZones for my cards. I apologize for my English... I know its not that great, but I think you get the point!


    Last sentence: how can I drop my UI elements on a 3D Cube and get a reaction from it?

    Thank you very much! :)
     
  2. Maurice94

    Maurice94

    Joined:
    Oct 9, 2019
    Posts:
    2
    I found a simple solution... just use World Space Canvas, do correct positioning... attach a box collider to your UI card object and add an additional box collider to your battlefield and set it as a trigger.. now you can work with all the built-in functions and instantiate objects in the scene, handle your lists from there and so on....