Author Topic: Layers / Raycast question  (Read 11568 times)

TheDavil

  • Guest
Layers / Raycast question
« on: May 27, 2012, 05:06:01 PM »
Hi all,

I'm trying to integrate NGUI into a project which already has a camera, and has raycasts affecting things.

I tried creating a new UI and setting it to the default layer. I can show a label on screen without issue but can't get it to respond to "click" when I touch the screen - I am using Android Remote.

Does this have something to do with layers or layermasks ?
Or am I just setting up the UI wrong (seperate to main camera) ?

Should my own raycast affect NGUI badly ? I thought both would work side-by-side ?

Sorry about the n00bishness

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Layers / Raycast question
« Reply #1 on: May 27, 2012, 05:28:29 PM »
You need to make sure your camera that sees the UI has UICamera script attached, or no events will be sent out. You also have to make sure that "Raycast Hit Triggers" option is checked in physics.

Lastly, you will probably want to keep your UI on something other than the default layer...

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #2 on: June 02, 2012, 06:24:02 AM »
Hi There,

I think I have the layer stuff sorted. I'm using a 3D Camera for the scene and a seperate 2d camera for the UI.
I sorted all the layer stuff with the help of Petey's video - http://www.youtube.com/watch?v=oTmNugGGwXo

I'm not too good with dept, culling masks etc - but I think I get that bit now.

However,

I still can't get any events to fire when I click / touch an image button/label/whatever
I put the basic script with the simple code

 OnPress(){ Debug.Log ("result!!!"); }

and I get nothing on the Console when I click on it in game view, or touch it on screen on Android Remote. (this is an Android project)

I've tried changing "Event Receiver Mask" in the UICamera script - and I've tried having the UICamera only on my main 3D camera, or just on the 2D UI one, or both. Nothing works.

I have the basic script applied to the Image Button, not the panel, or the UI root.

Here's my hierarchy
http://twitpic.com/9rxlpv/full

also I've tried turning off my own TouchMessages script, doesn't make a difference
also  UICamera.currentTouchID keeps outputting left clicks as -3 and then -100 from then on ????

I'm doing something horrendously stupid I'm almost sure of it, but if anybody could please help ???

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Layers / Raycast question
« Reply #3 on: June 02, 2012, 02:25:38 PM »
Did you check the "Raycast Hit Triggers" option as I suggested?

-3 is middle mouse button, so I'm not sure why you'd be getting that with the LMB. I'd suggest checking Unity's Input values at this point. Input.GetMouseButton(0) should give you the state of the left mouse button. If it gives you something else, you've got other (OS/driver) issues.

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #4 on: June 02, 2012, 04:17:22 PM »
yep "Raycast Hit Triggers" is turned on. I have other raycasts within my scene and they work fine. I'll double check Input.GetMouseButton(0) etc to make sure I'm not having mental problems. Maybe it's the Android remote causing problems, but while connected with it, I'm definitely clicking LMB. Thanks for your help on this.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Layers / Raycast question
« Reply #5 on: June 02, 2012, 04:18:45 PM »
Android remote? /facepalm I should have read your original post more carefully.

iOS and Android remote send both mouse and touch events. It's a known issue with Unity. You need to disable mouse events on the UICamera, then it will only handle touch.

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #6 on: June 06, 2012, 04:18:10 PM »
Hi there.

Sorry about the delay.
I've done that (turned off Mouse in UICamera) and it's still acting exactly the same.

Here's a screenshot.
http://www.twitpic.com/9tj0h5

when I move the mouse around it's constantly outputting lasttouchposition as the mouse pointer position. Also CurrentTouchID is -3 until I make my first press or click.

I think I'm going mad here :-(

loopyllama

  • Guest
Re: Layers / Raycast question
« Reply #7 on: June 06, 2012, 04:29:00 PM »
because labels do not have colliders. ngui needs a collider to register the hit.

select your label (or object that contains the OnPress script) and choose NGUI>Attach a Collider

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #8 on: June 07, 2012, 05:45:35 PM »
Ah. sounds easy. will test that out. Thanks!

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #9 on: June 13, 2012, 03:15:15 PM »
turns out it wasn't a missing collider. I had removed the UICamera script from the second (2D) camera and left it only on the main (3D) camera. I re-enabled the UICamera script and re-ticked everything. mouse,touch,keyboard etc. it seems to be working fine now.

one last thing though. Having issues with buttons where if I hit the label nothing happens, I have to make sure to hit the background "around" the text if you know what I mean.

Anyway, finally I might get somewhere with this. thanks for all your help. this is great software.

PhilipC

  • Guest
Re: Layers / Raycast question
« Reply #10 on: June 13, 2012, 03:29:10 PM »
Does the label of that button have a collider on it (maybe you accidentally added one after following the previous suggestions)?

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #11 on: June 18, 2012, 01:06:51 PM »
no it always had a collider.

TheDavil

  • Guest
Re: Layers / Raycast question
« Reply #12 on: June 18, 2012, 01:13:01 PM »
ahah you meant the label. Yes that's correct. Good job I did a double take just then.

Thanks