Hi all,
I am having trouble with my box collider for my 2D game.
The goal is that the player can examine an inventory item and when they click on it, the action list spawns a prefab item into the scene. This item will consist of a black semi-transparent screen that has a box collider attached to it to block out all the other hot spots in the scene.
The fully spawned inventory object will be this back screen, the sprite for the item, and then any additional hotspots on the item so players can interact with them.
My problem is that when I spawn my 2D screen onto my scene, it doesn't block any of the other hotpsots. I have a box Collider 2D setting on it and I have it spawing on the default setting. Not sure what I am missing!
The screen prefab blocks everything fine when I put it in the scene manually, it only seems to not work when spawned through an action list.
Any help is appreciated! Thanks.
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @naomih97. What are your AC/Unity versions?
The approach sounds solid - if it's a 2D Collider in a 2D scene, and on the Default layer, then it should indeed prevent clicks underneath.
Check the position that it's being spawned to - in particular, it's Z-position. If two Colliders overlap visually in 2D game, then the one closest to the camera is the one that's detected.
My object is spawning z position 0 and my camera is z position -10.
Just to test it out I have the object spawn in at z -9 and the camera at z -10 and still it won't block any hot spots.
Is the Hotspot on the root of the spawned object, or is it possible it has a local Z position that's bringing it closer to zero?
6000.2.14 is the Unity version. The AC version is shown at the bottom of the AC Game Editor window.
Aside from the z-depth, the y-position can also be a factor. In your Settings Manager's Hotspots panel, is Detect lowest overlapping Hotspot? visible and checked? Try toggling it if it's showing.
If that makes no difference, it may be best so share some screenshots that illustrate the issue, as well as the Hierarchy / setup of the spawned object.