I'm designing a tutorial for a Unity game and am stuck at what seems like a trivial problem. For every step in the tutorial, I guide the user by hiding everything on the screen except the buttons they need to press. My game hierarchy looks like this.
Button Canvas
Select_Me_Button
Dont_Select_Me_Button
Tutorial Canvas
Mask Group 1
Left Border Mask
Right Border Mask
Up Border Mask
Down Border Mask
Mask Group 2 ...
The TutorialCanvas GameObject has a Canvas component with a higher sorting order than ButtonCanvas. I added GraphicRaycaster Component with Blocking Mask set to everything and Blocking Objects set to None for the TutorialCanvas. However, even though TutorialCanvas renders on top of Button Canvas, I am still able to click through the mask and trigger buttons that are not supposed to be clickable. I was able to block clicks by adding image components functioning as masks to parent objects Mask Group 1 and Mask Group 2 belonging to TutorialCanvas, but this is not desirable, because I need to group the image components to create a mask, and gameobject can only accept 1 image component.
I'm having a hard time imagining this is so hard. I just need one canvas with a mask to block clicks going to a canvas behind it.
Thanks to the help on Unity Forum I solved the issue by creating a single group of masks and positioning them via RectTransform's anchoredPosition component in script.
Related
I just added 3D Text on my scene and it is invisible on the background of Canvas, that is "Render Mode: Screen Space - Camera". How i can make it visible on background of my canvas?
There are 2 ways to fix this:
Change the Sorting Layer of the obstructing object to be one behind that of the text, or change the Order in layer of the obstructing object to be lower than that of the canvas.
OR
Create a new canvas with a higher Sorting Layer (you may need to create a new one) or Order in Canvas and place the text in the new canvas.
As an example, here I have my normal text in a lower canvas, but I created an overlay canvas for text that absolutely must go above everything else.
I find that the second solution is a better general solution for the issue, as in the first solution you have to change the layers for every object in the scene that might obstruct your text.
So all i'm looking for is simple. I want the UI elements such as Buttons/Logo/..etc to be in front any particle effects in the Canvas.
In the answer Here someone suggested to add a canvas component to each and every UI element I want to show in front of the particles and that work somehow the only problem in this way the buttons won't click at all.
All elements are on the default sorting layer including the particles object and the camera.
Is that hard to do that?
Please help.
set "Order in layer" of Particles to 0 and UI elements to 1 or a better way of doing this is to go to add new layers, create a foreground and background layer, set foreground to 1 and background to 0 and then change from the default layer to which ever you want in front or back.
My solution was to change the material I was using in the particle system. Change "Sprite-Default" to a material with "Rendering Mode" Opaque and "Shader" to "Standard".
Hi I am trying to create custom buttons on unity (trapeziums). I successfully created the visible area on Photoshop and imported it as Sprite 2D UI as per the following image:
The issue arises, when I'm trying to select one of the buttons in game, their border overlap each other, since the transparent area is still being considered as part of the clickable button area. How can I remove this?
EDIT:
Practically when I import I want the squared boxes to not be counted with the image. I need the edges of the orange area to be cut flush with that and not the entire area(i.e. including the transparent boxes).
You may achieve this by using Alpha Hit Test Minimum Threshold. Take a look at this nice video tutorial.
There is one extra step that is not shown in the video but mentioned in the comments: you have to change "Mesh Type" to "Full Rect" and not "Tight" as it is.
Hope that helps.
The clickable area is based on the Rect Transform component of the GameObject. Adjust the width and height to the clickable area you want. You may have to crop your image in photoshop accordingly. If you select 'Gizmos' in the editor you can toggle viewing the click region.
I'm trying to create a pop-up window that will overlay on top of the current canvas and block all interaction with it. Everything I read says to use Canvas Group(s) and/or Graphic Raycaster, but I can't find the magic combination to make that work.
Canvas O is a Screen-Space overlay for typical buttons.
Canvas K is a World-Space canvas for my current UI stuff that I can pan around and whatnot.
Canvas P is my popup which is also an overlay and which I want to block all interaction with both O and K "behind" it. I've put a Canvas group on all 3, I've put a Graphic Raycaster on P, I've selected "Blocks Raycasts" in the Canvas Group of P as well as setting the "Blocking Objects" and "Blocking Mask" to All and Everything. I've put colliders on, and I've made the canvases different Sort Orders for layering. I'm out of ideas. Why won't it block??
Canvas UI objects are drawn in descending order (so that the lowest object under the canvas in the inspector is drawn last and is in front of everything else).
Like this:
Canvas
Text1
Text2 (drawn after Text1)
OverlayImage (drawn after Text1 and Text2, blocking raycasts)
If you add an image UI object to a canvas, drag it to be the lowest object under that canvas in the inspector like in the example above, then expand it so that it takes up the entire canvas, and set the anchors (which control resizing) to expand based on the width and height of the window, that image should always cover the entire canvas. As long as it stays as the lowest GameObject in the inspector hierarchy, it should block events underneath that on that canvas.
I'm not sure about one canvas blocking events on other canvases in the scene, but I would add OverlayImages on all of the canvases, and control whether the OverlayImages are enabled or disabled from canvas P in your example.
I'm currently writing up a UI-Centric game, and I've added a small image overlay over some elements on screen. However, the problem is that now I can't click any buttons behind this overlay image, regardless of transparency etc.
Just to chance it, I set up a new layer called "noUIclick" and set it to ignore every other layer under physics settings - long shot I know, but no dice. Tried also simply swapping to 3D view and moving the overlay image back on the z-axis.
Is there any easy way to set a layer for UI components which will entirely ignore/allow for passthrough of mouseclicks onto the buttons in the background?
On the Image component, uncheck raycastTarget.