#Can you try distilling this question
1 messages ยท Page 1 of 1 (latest)
@thorny thistle Having UI interact with in-game visual objects. There's a quick example as an image. Currently putting in a red tinted spot light darkens the game and only illuminates that area but the buttons are completely unaffected.
Don't use UI then
UI is not going to be affected by in-game lighting or whatever those things are
it's unclear what your "red-tinted-spot" is made of
Oh that's jus ta 2d light object
you would need to use SpriteRenderers to be affected by that
And yeah, UI is hard to work out since that little black box bottom left is the game area, but you can see the very bottom of the UI that's huge (referencing 1080x1920 on canvas)
this is how screen space overlay canvas works, yes
Not sure if I can reconcile both of them to properly overlay ๐คทโโ๏ธ
it's shown in the scene as 1 pixel = 1 unit
that's just how it looks in the scene view though
Yeah in game looks solid
Just hard to figure out what area I have left to work with
well you shouldn't be trying to line screen space UI up with world space objects
that will break anyway as soon as the game aspect ratio or resolution changes
Fair point, so when you say I shouldn't be using UI, what would be the next best thing?
As mentioned...
Ah my bad didn't recognise that was the solution, thought it was a workaround
My original reasoning for going the UI path was to simplify User input cross devices (mostly targeting mobile) Any idea if that would be a challenge or not overly concerning?
user input? Not a concern
You can use the same input mechanism UI has on game world objects
Just use scripts with IPointerClickHandler, give the sprites collider2ds, include an EventSsytem in your scene, and a GraphicRaycaster2D on the camera
So game world objects that must be clicked will have a Monobehaviour also implement IPointerClickHandler, they will obviously have the appropriate collider.
I'm hoping ๐ค the EventSystem I bring in from a separate scene would work just fine for this use case (on new input system, I know having multiples conflict or at least spam warnings) and I swear I saw a GraphicRaycaster2D before but.. can't find now on my camera ๐ซ
Ah, it's the canvas I saw the Graphic Raycaster on, not the camera
For Cinemachine, that would be on the VCam, correct? Or still the MainCamera itself?
actual camera
public class GameWorldClickHandler : MonoBehaviour, IPointerClickHandler
{
[SerializeField] private UnityEvent onClick;
public void OnPointerClick(PointerEventData eventData)
{
onClick?.Invoke();
}
}
Something like this to emulate similar OnClick logic to the usual UI Buttons?
๐
@thorny thistle It worked... but not fully ๐ฆ I put a cheeky comment to confirm it working but it only ever printed once:
[SerializeField] private UnityEvent onClick;
public void OnPointerClick(PointerEventData eventData)
{
onClick?.Invoke();
Log.Info("We got clicked boi");
}
you have Collapse enabled in your console window
My bad, the count remained 1
BUT after a while it did increase to two, and after clicking several dozen times it's now 4... It works, but something is a bit weird?
Oh... so it's something collider related. If I click the very top of the circle it works every time, just like a button would. But for most of the circle it doesn't.
Collider has no offset with a slightly bigger 0.7 radius... I'm going to assume it's because I scaled the circle? Does that throw off the collider?
Scaling back to 1 didn't fix anything, it seemed to make it worse. I can click only very specific spots in the circle, even when scaled up
I'll test a plain main camera instead of cinemachine
something is probably in the way
a ui element or another collider
there is no difference
cinemachine literally just positions your camera
it does nothing else
Thanks, from what I can tell... clickicking on the actual circle doesn't work, but just outside of it (that extra overlap I gave it from a bigger radius) seems to work. So it's the sprite itself interfering somehow? Doesn't make sense to me since the collider should be shared
Tried moving the sprite lower but it must be as you said, something else is capturing these clicks somehow. I'll try a plain scene just to test the logic for now