Reputation: 530
I'm working on making interactive tutorials for my game, where for example a hand image will guide the user where to click next and at the same time will also show some info about the game rules.
For example, in the attached image I created an inverted mask following this tutorial by code monkey https://www.youtube.com/watch?v=XJJl19N2KFM&t=80s
over button 1, I want the clicks to work on the circled area only. How can I achieve this?
Buttons are on a different canvas and all masking stuff are on another canvas.
Upvotes: 0
Views: 3850
Reputation: 1
For those who might wonder why suggestions from the Code Monkey video do not work in Unity 2021.3 - the code requires a few minor tweaks:
Final result:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Rendering;
public class UIMaskFilter : Image {
public override Material materialForRendering {
get {
Material material = new Material(base.materialForRendering);
material.SetFloat("_StencilComp", (float)CompareFunction.NotEqual);
return material;
}
}
}
Upvotes: 0
Reputation: 196
I recommend using UnmaskForUGUI. It is a free plugin and can be achieved by using UnmaskRaycastFilter
. I actually use it in my projects for the same purpose as yours.
Upvotes: 1