1

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.

enter image description here

3
  • Not what you asked but as an alternative solution I would: 1) create an image overlay over the entire screen blocking everything. 2) (de)activate exact duplicates of the buttons you already have at the same position with exactly the same callbacks assigned => only this/these exact button/s is/are clickable at all. ;) Commented Feb 19, 2021 at 7:21
  • Thanks, but I'm looking for a simpler solution. I've tried something like youve suggested, only to get bogged down in syntax. Im hoping to avoid scripting my way out of this. Commented Feb 19, 2021 at 8:29
  • 1
    Alternative might be using CanvasGroups or alternatively simple transparent Image components and you simply overlay each individual button with such an image/CanvasGroup => set the Image.raycastTarget/CanvasGroup.blocksRaycast for your allowed interactions per step Commented Feb 19, 2021 at 16:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.