Author Topic: Colliders and Alpha  (Read 1856 times)

Yukichu

  • Full Member
  • ***
  • Thank You
  • -Given: 3
  • -Receive: 8
  • Posts: 101
    • View Profile
Colliders and Alpha
« on: August 22, 2014, 08:16:55 AM »
Attempting to create "invisible" collider for UI.

Attempt 1:  UIWidget + Collider = fail
Attempt 2:  UISprite (Alpha 0) + Collider = fail
Attempt 3:  UISprite (Alpha 1/255) + Collider = success

I have it working and that's great, just wondering why UICamera.lastHit.collider doesn't register unless there is some alpha there, or am I mistaken?  Didn't change any other settings.

Mmmm... addendum, the panel is set to "Visible" so I am guessing it's checking for a visible component.  Not 100% sure, but this makes sense.  Will have to test more later.

RobBrooks

  • Newbie
  • *
  • Thank You
  • -Given: 5
  • -Receive: 0
  • Posts: 19
    • View Profile
Re: Colliders and Alpha
« Reply #1 on: August 22, 2014, 08:30:35 AM »

Yeah I had this too in a UIButton where I needed to make the UISprite disappear on rollover.
So I just gave the rollover colour an alpha of zero to clear it because that was the most direct way of doing it.
Unfortunately, this meant I was then unable to click the button once I'd rolled over it because there was effectively no graphical representation there and that appeared to defeat the process.
So I just set the alpha to 1/255 which was near transparent enough to be imperceptible.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Colliders and Alpha
« Reply #2 on: August 23, 2014, 03:08:21 AM »
UIWidget + Collider is the way to do it. ALT+SHIFT+W, ALT+SHIFT+C.

Not sure why you marked it as "fail". All sprites derive from UIWidget, and the alpha checking code comes straight from UIWidget.