Search Unity

Worldspace Camera UI Image disappears while dragging

Discussion in 'General Graphics' started by Ghidera, Feb 21, 2015.

  1. Ghidera

    Ghidera

    Joined:
    Mar 6, 2013
    Posts:
    53
    I've written a card game (basically Pogo's Aces Up with veriations). I have the basic game done and now I'm working on prettying it up with animations etc.

    I quickly found out that overlay mode means nothing other than UI elements appearing so I changed to camera. Particles show up no problem so I'm almost where I need to be.

    The problem I have now is that dragging a card (UI Image) makes the card disappear. I'm pretty sure it's simply because I'm setting the card anchorposition to the mouse position and the image is moving behind the canvas. The only way I can think of to fix this is after the move set that axis position back to the canvas.

    Is there a way to "lock" a particular axis of the UI Image or is there a better way to handle the movement that anyone knows?

    Thanks!
     
  2. Ghidera

    Ghidera

    Joined:
    Mar 6, 2013
    Posts:
    53
    Haven't solved this yet but I understand better now. The UI Image isn't behind the canvas, its outside it. I was moving the mouse around and the card just came into view from the top of the canvas when the mouse was at the very bottom. Something happens differently with the mouse and UI coordinates when using worldspace camera instead of overlay. I switched between using transform.position and recttransform.anchoredposition and the image still ends up outside the canvas (not sure if its the same position for both) so perhaps I'll try getting the change in mouse position and apply that to the anchoredposition rather than applying the mouseposition directly.
     
  3. Ghidera

    Ghidera

    Joined:
    Mar 6, 2013
    Posts:
    53
    levlaj, Billy4184 and ozgurdugmeci like this.
  4. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85
    thank you for the log.

    I had the same problem and i used the link you shared. It worked.
    Now ui button is visible while being dragged.
    next thing is, while i am dragging the button, there is a distance between mouse and button.
    why is this distance exist and how can i fix this?
    this is my code in java
    Code (JavaScript):
    1. function OnDrag (eventData :PointerEventData)
    2.     {
    3.         myRectTransform= itemDragged.GetComponent(RectTransform);
    4.         //var scaler = GetComponentInParent(UnityEngine.UI.CanvasScaler);
    5.         myRectTransform.anchoredPosition = new Vector2(Input.mousePosition.x , Input.mousePosition.y);
    6.      
    7.      
    8.      
    9.  
    10.     }
     
    Last edited: May 8, 2015
  5. ozgurdugmeci

    ozgurdugmeci

    Joined:
    Mar 1, 2015
    Posts:
    85