Search Unity

Problem with RectTransformUtility

Discussion in 'UGUI & TextMesh Pro' started by Kekmeister, Mar 17, 2016.

  1. Kekmeister

    Kekmeister

    Joined:
    Jan 21, 2016
    Posts:
    1
    Hi guys,
    i need your help using the function RectTransformUtility.RectangleContainsScreenPoint().
    Here is my situation: i've built a virtual joypad to control the player and i need to check each update if the knob middle point is contained into an image of my ui (the image is part of my virtual joypad); to do that i used the function above from RectTransformUtility class and all went good until i moved my camera as child of my player object, to obtain the first person view. Now i think that the problem is caused by the fact that RectangleContainsScreenPoint() takes the camera as last argument as stated in the documentation (http://docs.unity3d.com/ScriptReference/RectTransformUtility.RectangleContainsScreenPoint.html), but i can't figure out what it means "The camera from which the test is performed from." and "Does the RectTransform contain the screen point as seen from the given camera?".
    Do you guys think that i should use two different Cameras, one for UI and one to obtain the FP view?
     
  2. Caio_Lib

    Caio_Lib

    Joined:
    Mar 4, 2014
    Posts:
    83
    Hi Kekmeister,
    "The camera from which the test is performed from." is the camera that shows your image in Game View.

    PS: if your Canvas - Render Mode is Screen Space Overlay you should use null for Camera, otherwise use the Camera that shows your GameObject.
     
  3. Thorlar

    Thorlar

    Joined:
    Oct 7, 2017
    Posts:
    28
    So many thanks for this, and sorry for posting 2 years after, but this random obscure message saved the day :D