Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

UI Button raycast.

Discussion in 'UGUI & TextMesh Pro' started by littlesparta, Mar 14, 2015.

  1. littlesparta

    littlesparta

    Joined:
    Feb 11, 2015
    Posts:
    25
    Hi
    Iv previously posted this question before but I am still struggling and cant figure out where and how to fix my issue. I have created a world-space canvas containing buttons, however the raycast of each button is a little off centre and doesnt quite fit the exact button image. Does the raycast detection of each button depend on the size of image used? And does the scaling of the canvas/buttons affect it?

    I have tried looking into the example project of the new UI and cant find a solution :s If anyone could help that would be so awesome!
     
  2. SimonDarksideJ

    SimonDarksideJ

    Joined:
    Jul 3, 2012
    Posts:
    1,685
    The raycasting works off the RectTransform for any object that has a graphic component (image/rawimage or text).

    The only thing that can mess with it is the event camera. Are you using a specific camera with your WorldSpace UI or the main camera?

    I've not heard of any offset issues myself but you could try replacing the image as a test with the built in one's to see if you have the same effect.
     
  3. littlesparta

    littlesparta

    Joined:
    Feb 11, 2015
    Posts:
    25
    Im using UFPS so the character contains a FPS camera (which is the main one) and a secondary camera which displays weapons being drawn and held.
    I haven't actually set a specific camera in the canvas component, not sure if that will fix things? I will try playing around with the RectTransform. I took a page off the example you replied with from a previous post of mine exactly as they did it with the grouping of buttons but I will see if I need to tweak it.
     
  4. littlesparta

    littlesparta

    Joined:
    Feb 11, 2015
    Posts:
    25
    Ok I thought I would come back now that I figured what is causing my issue, it seems that the body object in UFPS us causing the problem. Il come back once I have a solution incase anyone else has the same issue in the future.
     
  5. Feaver1968

    Feaver1968

    Joined:
    Nov 16, 2014
    Posts:
    70
    You can probably fix this by moving the body to a layer that is ignored for raycasts
     
  6. littlesparta

    littlesparta

    Joined:
    Feb 11, 2015
    Posts:
    25
    Tried that :/